Documentation
¶
Index ¶
- Constants
- func ValidateSpecification(spec *Specification) error
- type ContextStats
- type DataGenerator
- type DefaultDataGenerator
- func (g *DefaultDataGenerator) Generate(schema *Schema, ctx *GenerationContext) (interface{}, error)
- func (g *DefaultDataGenerator) GetFormatGeneratorInfo() []FormatGeneratorInfo
- func (g *DefaultDataGenerator) GetRegisteredFormats() []string
- func (g *DefaultDataGenerator) GetSeed() int64
- func (g *DefaultDataGenerator) HasFormatGenerator(format string) bool
- func (g *DefaultDataGenerator) RegisterCustomFormat(format string, generator FormatGenerator)
- func (g *DefaultDataGenerator) RegisterFormatGenerator(format string, generator FormatGenerator)
- func (g *DefaultDataGenerator) RemoveFormatGenerator(format string)
- func (g *DefaultDataGenerator) SetLocale(locale string)
- func (g *DefaultDataGenerator) SetSeed(seed int64)
- type Endpoint
- type ExampleObject
- type FormatGenerator
- type FormatGeneratorInfo
- type GenerationContext
- func (ctx *GenerationContext) Clone() *GenerationContext
- func (ctx *GenerationContext) GetArrayKey(arrayName string) string
- func (ctx *GenerationContext) GetArraySize(key string) int
- func (ctx *GenerationContext) GetContextKey(schemaType string) string
- func (ctx *GenerationContext) GetDepthRemaining() int
- func (ctx *GenerationContext) GetObjectKey(objectName string) string
- func (ctx *GenerationContext) GetStats() ContextStats
- func (ctx *GenerationContext) HasArraySize(key string) bool
- func (ctx *GenerationContext) IsAtMaxDepth() bool
- func (ctx *GenerationContext) IsCircularReference(key string) bool
- func (ctx *GenerationContext) IsNearMaxDepth() bool
- func (ctx *GenerationContext) MarkVisited(key string)
- func (ctx *GenerationContext) Reset()
- func (ctx *GenerationContext) SetArraySize(key string, size int)
- func (ctx *GenerationContext) ShouldSkipOptionalField(fieldName string) bool
- func (ctx *GenerationContext) String() string
- func (ctx *GenerationContext) UnmarkVisited(key string)
- func (ctx *GenerationContext) Validate() ValidationResult
- func (ctx *GenerationContext) WithDepthIncrement() *GenerationContext
- func (ctx *GenerationContext) WithParent(parent string) *GenerationContext
- func (ctx *GenerationContext) WithRequired(required bool) *GenerationContext
- type GenerationContextEnhanced
- type Header
- type InfoObject
- type MediaTypeObject
- type OpenAPIParser
- type Operation
- type Parameter
- type PathItem
- type RequestBody
- type Response
- type Schema
- type SecurityRequirement
- type SpecParser
- type Specification
- type ValidationResult
Constants ¶
const ( // String formats FormatDateTime = "date-time" FormatDate = "date" FormatTime = "time" FormatEmail = "email" FormatURI = "uri" FormatURL = "url" FormatUUID = "uuid" FormatHostname = "hostname" FormatIPv4 = "ipv4" FormatIPv6 = "ipv6" FormatPassword = "password" FormatByte = "byte" FormatBinary = "binary" // Number formats FormatFloat = "float" FormatDouble = "double" // Integer formats FormatInt32 = "int32" FormatInt64 = "int64" )
Standard OpenAPI formats as defined in the specification
Variables ¶
This section is empty.
Functions ¶
func ValidateSpecification ¶
func ValidateSpecification(spec *Specification) error
ValidateSpecification validates an OpenAPI specification
Types ¶
type ContextStats ¶
type ContextStats struct {
MaxDepth int `json:"max_depth"`
CurrentDepth int `json:"current_depth"`
DepthRemaining int `json:"depth_remaining"`
VisitedCount int `json:"visited_count"`
ArraySizesCount int `json:"array_sizes_count"`
IsAtMaxDepth bool `json:"is_at_max_depth"`
IsNearMaxDepth bool `json:"is_near_max_depth"`
}
ContextStats provides statistics about the generation context
type DataGenerator ¶
type DataGenerator interface {
// Generate creates mock data based on the provided schema and context
Generate(schema *Schema, ctx *GenerationContext) (interface{}, error)
// SetSeed sets the random seed for deterministic generation
SetSeed(seed int64)
// SetLocale sets the locale for data generation
SetLocale(locale string)
}
DataGenerator defines the interface for mock data generation
type DefaultDataGenerator ¶
type DefaultDataGenerator struct {
// contains filtered or unexported fields
}
DefaultDataGenerator is the default implementation of DataGenerator
func NewDefaultDataGenerator ¶
func NewDefaultDataGenerator() *DefaultDataGenerator
NewDefaultDataGenerator creates a new DefaultDataGenerator instance
func NewDefaultDataGeneratorWithSeed ¶
func NewDefaultDataGeneratorWithSeed(seed int64) *DefaultDataGenerator
NewDefaultDataGeneratorWithSeed creates a new DefaultDataGenerator with a specific seed
func (*DefaultDataGenerator) Generate ¶
func (g *DefaultDataGenerator) Generate(schema *Schema, ctx *GenerationContext) (interface{}, error)
Generate generates mock data based on the provided schema and context
func (*DefaultDataGenerator) GetFormatGeneratorInfo ¶
func (g *DefaultDataGenerator) GetFormatGeneratorInfo() []FormatGeneratorInfo
GetFormatGeneratorInfo returns information about all registered format generators
func (*DefaultDataGenerator) GetRegisteredFormats ¶
func (g *DefaultDataGenerator) GetRegisteredFormats() []string
GetRegisteredFormats returns a list of all registered formats
func (*DefaultDataGenerator) GetSeed ¶
func (g *DefaultDataGenerator) GetSeed() int64
GetSeed returns the current seed value
func (*DefaultDataGenerator) HasFormatGenerator ¶
func (g *DefaultDataGenerator) HasFormatGenerator(format string) bool
HasFormatGenerator checks if a format generator is registered
func (*DefaultDataGenerator) RegisterCustomFormat ¶
func (g *DefaultDataGenerator) RegisterCustomFormat(format string, generator FormatGenerator)
RegisterCustomFormat allows registration of custom format generators
func (*DefaultDataGenerator) RegisterFormatGenerator ¶
func (g *DefaultDataGenerator) RegisterFormatGenerator(format string, generator FormatGenerator)
RegisterFormatGenerator registers a custom format generator
func (*DefaultDataGenerator) RemoveFormatGenerator ¶
func (g *DefaultDataGenerator) RemoveFormatGenerator(format string)
RemoveFormatGenerator removes a format generator
func (*DefaultDataGenerator) SetLocale ¶
func (g *DefaultDataGenerator) SetLocale(locale string)
SetLocale sets the locale for data generation
func (*DefaultDataGenerator) SetSeed ¶
func (g *DefaultDataGenerator) SetSeed(seed int64)
SetSeed sets the random seed for deterministic generation
type Endpoint ¶
type Endpoint struct {
Path string
Method string
OperationID string
Parameters []Parameter
Responses map[string]Response
Operation *Operation
}
Endpoint represents a single API endpoint
type ExampleObject ¶
type ExampleObject struct {
Summary string `json:"summary,omitempty"`
Description string `json:"description,omitempty"`
Value interface{} `json:"value,omitempty"`
ExternalValue string `json:"externalValue,omitempty"`
}
ExampleObject represents an example value with metadata
type FormatGenerator ¶
type FormatGenerator func(schema *Schema, ctx *GenerationContext) (interface{}, error)
FormatGenerator defines a function type for format-specific data generation
type FormatGeneratorInfo ¶
type FormatGeneratorInfo struct {
Format string `json:"format"`
Description string `json:"description"`
Example string `json:"example"`
}
FormatGeneratorInfo provides information about format generators
type GenerationContext ¶
type GenerationContext struct {
MaxDepth int
CurrentDepth int
Visited map[string]bool
ArraySizes map[string]int
Required bool
Parent string
Locale string
Seed int64
Timestamp time.Time
RequestedExample string // Header X-Mock-Example value for selecting specific examples
}
GenerationContext provides context for data generation
func NewGenerationContext ¶
func NewGenerationContext() *GenerationContext
NewGenerationContext creates a new generation context with default values
func NewGenerationContextWithConfig ¶
func NewGenerationContextWithConfig(maxDepth int, seed int64, locale string, defaultArraySize int, preferExamples bool) *GenerationContext
NewGenerationContextWithConfig creates a new generation context with configuration
func NewGenerationContextWithExample ¶
func NewGenerationContextWithExample(maxDepth int, seed int64, locale string, defaultArraySize int, preferExamples bool, requestedExample string) *GenerationContext
NewGenerationContextWithExample creates a new generation context with example selection
func (*GenerationContext) Clone ¶
func (ctx *GenerationContext) Clone() *GenerationContext
Clone creates a deep copy of the generation context
func (*GenerationContext) GetArrayKey ¶
func (ctx *GenerationContext) GetArrayKey(arrayName string) string
GetArrayKey generates a unique key for array tracking
func (*GenerationContext) GetArraySize ¶
func (ctx *GenerationContext) GetArraySize(key string) int
GetArraySize returns the stored array size for a given key, or 0 if not set
func (*GenerationContext) GetContextKey ¶
func (ctx *GenerationContext) GetContextKey(schemaType string) string
GetContextKey generates a unique key for the current context state
func (*GenerationContext) GetDepthRemaining ¶
func (ctx *GenerationContext) GetDepthRemaining() int
GetDepthRemaining returns the number of depth levels remaining
func (*GenerationContext) GetObjectKey ¶
func (ctx *GenerationContext) GetObjectKey(objectName string) string
GetObjectKey generates a unique key for object tracking
func (*GenerationContext) GetStats ¶
func (ctx *GenerationContext) GetStats() ContextStats
GetStats returns statistics about the current context state
func (*GenerationContext) HasArraySize ¶
func (ctx *GenerationContext) HasArraySize(key string) bool
HasArraySize checks if an array size is stored for a given key
func (*GenerationContext) IsAtMaxDepth ¶
func (ctx *GenerationContext) IsAtMaxDepth() bool
IsAtMaxDepth checks if the current depth has reached the maximum
func (*GenerationContext) IsCircularReference ¶
func (ctx *GenerationContext) IsCircularReference(key string) bool
IsCircularReference checks if we're in a circular reference situation
func (*GenerationContext) IsNearMaxDepth ¶
func (ctx *GenerationContext) IsNearMaxDepth() bool
IsNearMaxDepth checks if the current depth is close to maximum (within 1 level)
func (*GenerationContext) MarkVisited ¶
func (ctx *GenerationContext) MarkVisited(key string)
MarkVisited marks a key as visited to prevent circular references
func (*GenerationContext) Reset ¶
func (ctx *GenerationContext) Reset()
Reset resets the context to initial state but preserves configuration
func (*GenerationContext) SetArraySize ¶
func (ctx *GenerationContext) SetArraySize(key string, size int)
SetArraySize stores an array size for a given key
func (*GenerationContext) ShouldSkipOptionalField ¶
func (ctx *GenerationContext) ShouldSkipOptionalField(fieldName string) bool
ShouldSkipOptionalField determines if an optional field should be skipped based on context
func (*GenerationContext) String ¶
func (ctx *GenerationContext) String() string
String returns a string representation of the context for debugging
func (*GenerationContext) UnmarkVisited ¶
func (ctx *GenerationContext) UnmarkVisited(key string)
UnmarkVisited removes a key from visited to allow revisiting in different paths
func (*GenerationContext) Validate ¶
func (ctx *GenerationContext) Validate() ValidationResult
Validate validates the generation context configuration
func (*GenerationContext) WithDepthIncrement ¶
func (ctx *GenerationContext) WithDepthIncrement() *GenerationContext
WithDepthIncrement returns a new context with incremented depth
func (*GenerationContext) WithParent ¶
func (ctx *GenerationContext) WithParent(parent string) *GenerationContext
WithParent returns a new context with a new parent path
func (*GenerationContext) WithRequired ¶
func (ctx *GenerationContext) WithRequired(required bool) *GenerationContext
WithRequired returns a new context with required flag set
type GenerationContextEnhanced ¶
type GenerationContextEnhanced struct {
MaxDepth int `json:"max_depth"`
CurrentDepth int `json:"current_depth"`
Visited map[string]bool `json:"visited"`
ArraySizes map[string]int `json:"array_sizes"`
Required bool `json:"required"`
Parent string `json:"parent"`
Locale string `json:"locale"`
Seed int64 `json:"seed"`
Timestamp time.Time `json:"timestamp"`
PreferExamples bool `json:"prefer_examples"`
DefaultArraySize int `json:"default_array_size"`
CircularRefCount map[string]int `json:"circular_ref_count"`
Path []string `json:"path"`
}
GenerationContext provides enhanced context for data generation with improved circular reference detection
type Header ¶
type Header struct {
Description string `json:"description,omitempty"`
Schema *Schema `json:"schema,omitempty"`
}
Header represents a header
type InfoObject ¶
type InfoObject struct {
Title string `json:"title"`
Description string `json:"description,omitempty"`
Version string `json:"version"`
}
InfoObject represents the info section of OpenAPI spec
type MediaTypeObject ¶
type MediaTypeObject struct {
Schema *Schema `json:"schema,omitempty"`
Example interface{} `json:"example,omitempty"`
Examples map[string]ExampleObject `json:"examples,omitempty"`
}
MediaTypeObject represents a media type
type OpenAPIParser ¶
type OpenAPIParser struct {
// contains filtered or unexported fields
}
OpenAPIParser implements SpecParser using kin-openapi
func (*OpenAPIParser) GetEndpoints ¶
func (p *OpenAPIParser) GetEndpoints() []Endpoint
GetEndpoints returns all extracted endpoints
func (*OpenAPIParser) GetSchemas ¶
func (p *OpenAPIParser) GetSchemas() map[string]*Schema
GetSchemas returns all extracted schemas
func (*OpenAPIParser) Parse ¶
func (p *OpenAPIParser) Parse(data []byte) (*Specification, error)
Parse parses OpenAPI specification from bytes
func (*OpenAPIParser) Validate ¶
func (p *OpenAPIParser) Validate(spec *Specification) error
Validate validates the OpenAPI specification
type Operation ¶
type Operation struct {
OperationID string `json:"operationId,omitempty"`
Summary string `json:"summary,omitempty"`
Description string `json:"description,omitempty"`
Parameters []Parameter `json:"parameters,omitempty"`
RequestBody *RequestBody `json:"requestBody,omitempty"`
Responses map[string]Response `json:"responses"`
}
Operation represents an operation on a path
type Parameter ¶
type Parameter struct {
Name string `json:"name"`
In string `json:"in"` // query, header, path, cookie
Description string `json:"description,omitempty"`
Required bool `json:"required,omitempty"`
Schema *Schema `json:"schema,omitempty"`
}
Parameter represents a parameter in an operation
type PathItem ¶
type PathItem struct {
GET *Operation `json:"get,omitempty"`
POST *Operation `json:"post,omitempty"`
PUT *Operation `json:"put,omitempty"`
DELETE *Operation `json:"delete,omitempty"`
PATCH *Operation `json:"patch,omitempty"`
}
PathItem represents a single path in OpenAPI spec
type RequestBody ¶
type RequestBody struct {
Description string `json:"description,omitempty"`
Content map[string]MediaTypeObject `json:"content"`
Required bool `json:"required,omitempty"`
}
RequestBody represents a request body
type Response ¶
type Response struct {
Description string `json:"description"`
Content map[string]MediaTypeObject `json:"content,omitempty"`
Headers map[string]Header `json:"headers,omitempty"`
}
Response represents a response
type Schema ¶
type Schema struct {
Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
Description string `json:"description,omitempty"`
Enum []interface{} `json:"enum,omitempty"`
Default interface{} `json:"default,omitempty"`
Example interface{} `json:"example,omitempty"`
Examples map[string]ExampleObject `json:"examples,omitempty"`
Properties map[string]*Schema `json:"properties,omitempty"`
Items *Schema `json:"items,omitempty"`
Required []string `json:"required,omitempty"`
AdditionalProperties interface{} `json:"additionalProperties,omitempty"`
Pattern string `json:"pattern,omitempty"`
Minimum *float64 `json:"minimum,omitempty"`
Maximum *float64 `json:"maximum,omitempty"`
MinItems *int `json:"minItems,omitempty"`
MaxItems *int `json:"maxItems,omitempty"`
MinLength *int `json:"minLength,omitempty"`
MaxLength *int `json:"maxLength,omitempty"`
}
Schema represents a JSON Schema
type SecurityRequirement ¶
SecurityRequirement represents a security requirement
type SpecParser ¶
type SpecParser interface {
Parse(data []byte) (*Specification, error)
Validate(spec *Specification) error
GetEndpoints() []Endpoint
GetSchemas() map[string]*Schema
}
SpecParser defines the interface for OpenAPI specification parsing
type Specification ¶
type Specification struct {
Version string `json:"version"`
Info InfoObject `json:"info"`
Paths map[string]PathItem `json:"paths"`
Schemas map[string]*Schema `json:"schemas"`
Security []SecurityRequirement `json:"security"`
}
Specification represents a parsed OpenAPI specification
func LoadSpecification ¶
func LoadSpecification(specPath string) (*Specification, error)
LoadSpecification loads an OpenAPI specification from a file
type ValidationResult ¶
ValidationResult represents the result of context validation