Documentation
¶
Overview ¶
Package schemaexec provides symbolic execution of jq queries over JSON schemas.
Index ¶
- func ArrayType(items *oas3.Schema) *oas3.Schema
- func BoolType() *oas3.Schema
- func Bottom() *oas3.Schema
- func BuildArray(items *oas3.Schema, elements []*oas3.Schema) *oas3.Schema
- func BuildObject(props map[string]*oas3.Schema, required []string) *oas3.Schema
- func ConstBool(b bool) *oas3.Schema
- func ConstInteger(n int64) *oas3.Schema
- func ConstNull() *oas3.Schema
- func ConstNumber(n float64) *oas3.Schema
- func ConstString(s string) *oas3.Schema
- func GetProperty(obj *oas3.Schema, key string, opts SchemaExecOptions) *oas3.Schema
- func HasProperty(obj *oas3.Schema, key string, opts SchemaExecOptions) *oas3.Schema
- func IntegerType() *oas3.Schema
- func Intersect(a, b *oas3.Schema, opts SchemaExecOptions) *oas3.Schema
- func MergeObjects(a, b *oas3.Schema, opts SchemaExecOptions) *oas3.Schema
- func MightBeArray(s *oas3.Schema) bool
- func MightBeNumber(s *oas3.Schema) bool
- func MightBeObject(s *oas3.Schema) bool
- func MightBeString(s *oas3.Schema) bool
- func NullType() *oas3.Schema
- func NumberType() *oas3.Schema
- func ObjectType() *oas3.Schema
- func RequireType(s *oas3.Schema, typ oas3.SchemaType, opts SchemaExecOptions) *oas3.Schema
- func StringType() *oas3.Schema
- func TestExecuteShorthand(t *testing.T)
- func Top() *oas3.Schema
- func Union(schemas []*oas3.Schema, opts SchemaExecOptions) *oas3.Schema
- type AValue
- type Closure
- type LogLevel
- type Logger
- type PathSegment
- type PathWildcard
- type SValue
- type SchemaExecOptions
- type SchemaExecResult
- type SchemaLogOptions
- type ValueKind
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bottom ¶
Bottom returns a schema that matches nothing (the "never" type). By convention, we use nil to represent Bottom/Never.
func BuildArray ¶
BuildArray creates an array schema from element schemas.
func BuildObject ¶
BuildObject creates an object schema from property map. Simplified version for Phase 1.
func ConstInteger ¶
ConstInteger creates a schema for a specific integer.
func ConstNumber ¶
ConstNumber creates a schema for a specific number.
func ConstString ¶
ConstString creates a schema for a specific string literal.
func GetProperty ¶
GetProperty extracts the schema for a property from an object schema. Simplified version for Phase 1.
func HasProperty ¶
HasProperty refines an object schema to require a property exists. Used for guards like: select(has("foo"))
func IntegerType ¶
IntegerType creates a basic integer schema (unconstrained).
func Intersect ¶
func Intersect(a, b *oas3.Schema, opts SchemaExecOptions) *oas3.Schema
Intersect creates a schema that matches all input schemas (allOf). This is used for narrowing and constraint combination.
func MergeObjects ¶
func MergeObjects(a, b *oas3.Schema, opts SchemaExecOptions) *oas3.Schema
MergeObjects combines two object schemas (for the + operator on objects).
func MightBeArray ¶
MightBeArray checks if schema could be an array.
func MightBeNumber ¶
MightBeNumber checks if schema could be a number.
func MightBeObject ¶
MightBeObject checks if schema could be an object.
func MightBeString ¶
MightBeString checks if schema could be a string.
func NumberType ¶
NumberType creates a basic number schema (unconstrained).
func ObjectType ¶
ObjectType creates a basic object schema (unconstrained).
func RequireType ¶
func RequireType(s *oas3.Schema, typ oas3.SchemaType, opts SchemaExecOptions) *oas3.Schema
RequireType narrows a schema to a specific type. Used for type guards like: select(type == "array")
func StringType ¶
StringType creates a basic string schema (unconstrained).
func TestExecuteShorthand ¶
Types ¶
type AValue ¶
AValue is the abstract value stored on the symbolic VM stack. Phase 1a: only VSchema is used by the existing code. VClosure will be used in Phase 1b+.
func NewClosureValue ¶
func NewSchemaValue ¶
NewSchemaValue constructs an AValue containing a Schema.
type Closure ¶
Closure abstracts a function value captured by pushpc. PC is the entry address, ScopeIndex is the captured lexical scope index.
type LogLevel ¶
type LogLevel int
LogLevel represents the severity level for logs.
func ParseLogLevel ¶
ParseLogLevel parses a string into a LogLevel.
type Logger ¶
type Logger interface {
// Debugf, Infof, Warnf, Errorf log formatted messages at respective levels.
Debugf(format string, args ...any)
Infof(format string, args ...any)
Warnf(format string, args ...any)
Errorf(format string, args ...any)
// With returns a child logger augmented with the provided fields.
With(fields map[string]any) Logger
}
Logger is the interface used by the executor for logging.
type PathSegment ¶
type PathSegment struct {
Key interface{} // string (property), int (array index), or PathWildcard (symbolic)
IsSymbolic bool // True if this is a wildcard from .[] iteration
}
PathSegment represents one segment of a path expression
type PathWildcard ¶
type PathWildcard struct{}
PathWildcard represents a symbolic array index (from .[])
type SValue ¶
SValue wraps a schema for the schema VM stack. This is the value type that flows through the schema virtual machine.
type SchemaExecOptions ¶
type SchemaExecOptions struct {
// Limits to prevent combinatorial explosion
AnyOfLimit int // Max branches in anyOf before widening (default: 10)
EnumLimit int // Max enum values before widening to plain type (default: 50)
MaxDepth int // Max recursion depth (default: 100)
// Behavior flags
StrictMode bool // If true, fail on unsupported ops; if false, widen to Top (default: false)
EnableWarnings bool // If true, collect precision-loss warnings (default: true)
EnableMemo bool // If true, enable memoization for performance (default: true)
// Widening level controls how aggressively we simplify schemas
// 0 = none (keep all precision)
// 1 = conservative (keep types, drop facets when limits exceeded)
// 2 = aggressive (collapse to Top when limits exceeded)
WideningLevel int // default: 1
// Logging configuration
LogLevel string // Log level: "error", "warn", "info", "debug" (default: "warn")
LogMaxEnumValues int // Max enum values to show in logs (default: 5)
LogMaxProps int // Max object properties to show in logs (default: 5)
LogStackPreviewDepth int // Max stack depth to preview in logs (default: 3)
LogSchemaDeltas bool // If true, include schema deltas in debug logs (default: true)
}
SchemaExecOptions configures symbolic execution behavior.
func DefaultOptions ¶
func DefaultOptions() SchemaExecOptions
DefaultOptions returns the default configuration for schema execution.
type SchemaExecResult ¶
type SchemaExecResult struct {
Schema *oas3.Schema // The resulting schema after transformation
Warnings []string // Warnings about precision loss or unsupported operations
}
SchemaExecResult contains the output schema and diagnostic information.
func ExecSchema ¶
func ExecSchema(ctx context.Context, code *gojq.Code, input *oas3.Schema, opts SchemaExecOptions) (*SchemaExecResult, error)
ExecSchema executes compiled jq bytecode symbolically on an input schema. This is the core execution function - Phase 2 implementation.
func RunSchema ¶
func RunSchema(ctx context.Context, query *gojq.Query, input *oas3.Schema, opts ...SchemaExecOptions) (*SchemaExecResult, error)
RunSchema executes a jq query symbolically on an input JSON Schema. It parses and compiles the query, then performs symbolic execution to compute the output schema.
Example:
query, _ := gojq.Parse(".foo.bar")
inputSchema := &oas3.Schema{...}
result, err := schemaexec.RunSchema(context.Background(), query, inputSchema)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Output schema: %+v\n", result.Schema)
func (*SchemaExecResult) String ¶
func (r *SchemaExecResult) String() string
String returns a string representation of the result for debugging.