Documentation
¶
Index ¶
- Constants
- func NewFileSystemDocumentFetcher(config FileSystemFetchOptions) (documentFetcherInterface, error)
- func NewHttpDocumentFetcher(parserConfig HTTPFetchOptions) (documentFetcherInterface, error)
- func NewIfStatement(node schemaNode, nodePath string) ifStatement
- func NewOneOfConstraint(node schemaNode, metadata *parserMetadata) (*oneOfConstraint, error)
- type DocumentFetchOptions
- type FileSystemFetchOptions
- type Generator
- type GeneratorOptions
- type HTTPFetchOptions
- type ParserOptions
- type RootGenerator
- func ParseSchema(schema []byte, opts *ParserOptions) (RootGenerator, error)
- func ParseSchemaFile(path string, opts *ParserOptions) (RootGenerator, error)
- func ParseSchemaFileWithDefaults(path string) (RootGenerator, error)
- func ParseSchemaString(schema string, opts *ParserOptions) (RootGenerator, error)
- func ParseSchemaStringWithDefaults(schema string) (RootGenerator, error)
- func ParseSchemaWithDefaults(schema []byte) (RootGenerator, error)
Constants ¶
const MaxInt = math.MaxInt32 - 1
const MinInt = math.MinInt32 + 1
Given we shift the bounds +1 or -1 we need to ensure we don't overflow
Variables ¶
This section is empty.
Functions ¶
func NewFileSystemDocumentFetcher ¶ added in v0.2.0
func NewFileSystemDocumentFetcher(config FileSystemFetchOptions) (documentFetcherInterface, error)
func NewHttpDocumentFetcher ¶ added in v0.2.0
func NewHttpDocumentFetcher(parserConfig HTTPFetchOptions) (documentFetcherInterface, error)
func NewIfStatement ¶ added in v0.2.0
func NewIfStatement(node schemaNode, nodePath string) ifStatement
Internal if statement used to apply the if then then else logic
func NewOneOfConstraint ¶ added in v0.2.0
func NewOneOfConstraint(node schemaNode, metadata *parserMetadata) (*oneOfConstraint, error)
Types ¶
type DocumentFetchOptions ¶ added in v0.2.0
type DocumentFetchOptions struct {
// HTTP Fetch Options
HTTPFetchOptions HTTPFetchOptions
// File System Fetch Options
FileSystemFetchOptions FileSystemFetchOptions
}
Options for fetching external documents during parsing. Should be used with cautions Especially if schemas passed to the schema faker can be from untrusted sources.
type FileSystemFetchOptions ¶ added in v0.2.0
type FileSystemFetchOptions struct {
// If go-chaff is allowed to access the file system to resolve schema references
// THIS SHOULD BE DISABLED UNLESS YOU REALLY REALLY NEED IT
// Please if doing so, limit the AllowedPaths field as much as possible )
Enabled bool
// Overrides allowOutsideCwd to specifically allow for access to a list of paths schemas might reference
// relative paths will be resolved against the current working directory at the time the parser is initialized
// Symlinks that resolve to outside of the allowed paths will still be blocked
AllowedPaths []string
// Failsafe to prevent directory traversal attacks
AllowOutsideCwd bool
}
Options for fetching external documents from the file system
type Generator ¶
type Generator interface {
fmt.Stringer
Generate(*GeneratorOptions) interface{}
}
type GeneratorOptions ¶
type GeneratorOptions struct {
// The source of randomness to use for the given generation.
// Please note that some parts of the generators use different sources of randomness.
// ("regex" generation and "format" strings)
Rand *rand.RandUtil
// The default minimum number value
DefaultNumberMinimum int
// The default maximum number value
DefaultNumberMaximum int
// The default minimum String length
DefaultStringMinLength int
// The default maximum String length
DefaultStringMaxLength int
// The default minimum array length
DefaultArrayMinItems int
// The default maximum array length
// This will be set min + this inf the event a minimum value is set
DefaultArrayMaxItems int
// The default minimum object properties (Will be ignored if there are fewer properties available)
DefaultObjectMinProperties int
// The default maximum object properties (Will be ignored if there are fewer properties available)
DefaultObjectMaxProperties int
// The maximum number of references to resolve at once (Default: 10)
MaximumReferenceDepth int
// In the event that schemas are recursive there is a good chance the generator
// can run forever. This option will bypass the check for cyclic references
// Please defer to the MaximumReferenceDepth option if possible when using this
BypassCyclicReferenceCheck bool
// Used to keep track of references during a resolution cycle (Used internally and can be ignored)
ReferenceResolver referenceResolver
// Though technically in some cases a schema may allow for additional
// values it might not always be desireable. this option suppresses fallback_n values
// so that they will only appear to make up a "minimum value" forces them to
SuppressFallbackValues bool
// The maximum number of times to attempt to generate a unique value
// when using unique* constraints in schemas
MaximumUniqueGeneratorAttempts int
// The maximum number of times to attempt to satisfy "if" statements
// before giving up
MaximumIfAttempts int
// The maximum number of times to attempt to satisfy "oneOf" statements
// before giving up
MaximumOneOfAttempts int
// The maximum number of steps to take when generating a value
// after which the the generator will begin to do the "bare minimum" to generate a value
MaximumGenerationSteps int
// The maximum number of steps to take before giving up entirely and aborting generation
// This is a hard cap on generation steps to prevent extremely long generation times
CutoffGenerationSteps int
// contains filtered or unexported fields
}
func (*GeneratorOptions) ShouldCutoff ¶ added in v0.2.0
func (g *GeneratorOptions) ShouldCutoff() bool
func (*GeneratorOptions) ShouldMinimize ¶ added in v0.2.0
func (g *GeneratorOptions) ShouldMinimize() bool
type HTTPFetchOptions ¶ added in v0.2.0
type HTTPFetchOptions struct {
// If go-chaff is allowed to make HTTP requests to resolve schema references
Enabled bool
// Allowed hosts to fetch from (If empty, all hosts are allowed)
AllowedHosts []string
// Allow insecure connections (http)
AllowInsecure bool
}
Options for fetching external documents over HTTP
type ParserOptions ¶
type ParserOptions struct {
// Options for the regex generator used for generating strings with the "pattern property"
RegexStringOptions *regen.GeneratorArgs
// Options for the regex generator used for pattern properties
RegexPatternPropertyOptions *regen.GeneratorArgs
// Parser fetch configurations for external document fetching
DocumentFetchOptions DocumentFetchOptions
// Base path to resolve relative document references against for $ref resolution when fetching external documents
RelativeTo string
}
Options to take into account when parsing a json schema
type RootGenerator ¶
type RootGenerator struct {
Generator Generator
// For any "$defs"
Defs map[string]Generator
// For any "definitions"
Definitions map[string]Generator
// Metadata related to parser operations
Metadata *parserMetadata
}
Root generator a given schema. Call the Generate method on this to generate a value
func ParseSchema ¶
func ParseSchema(schema []byte, opts *ParserOptions) (RootGenerator, error)
Parses a Json Schema byte array. If there is an error parsing the schema, an error will be returned.
func ParseSchemaFile ¶
func ParseSchemaFile(path string, opts *ParserOptions) (RootGenerator, error)
Parses a Json Schema file at the given path. If there is an error reading the file or parsing the schema, an error will be returned
func ParseSchemaFileWithDefaults ¶
func ParseSchemaFileWithDefaults(path string) (RootGenerator, error)
Parses a Json Schema file at the given path with default options. If there is an error reading the file or parsing the schema, an error will be returned
func ParseSchemaString ¶
func ParseSchemaString(schema string, opts *ParserOptions) (RootGenerator, error)
Parses a Json Schema string. If there is an error parsing the schema, an error will be returned.
func ParseSchemaStringWithDefaults ¶
func ParseSchemaStringWithDefaults(schema string) (RootGenerator, error)
func ParseSchemaWithDefaults ¶
func ParseSchemaWithDefaults(schema []byte) (RootGenerator, error)
Parses a Json Schema byte array with default options. If there is an error parsing the schema, an error will be returned.
func (RootGenerator) Generate ¶
func (g RootGenerator) Generate(opts *GeneratorOptions) interface{}
Generates values based on the passed options
func (RootGenerator) GenerateWithDefaults ¶
func (g RootGenerator) GenerateWithDefaults() interface{}
func (RootGenerator) String ¶
func (g RootGenerator) String() string
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
jsonschema
Credit to https://github.com/santhosh-tekuri/jsonschema vendored from https://github.com/kaptinlin/jsonschema/blob/main/formats.go to keep size smaller
|
Credit to https://github.com/santhosh-tekuri/jsonschema vendored from https://github.com/kaptinlin/jsonschema/blob/main/formats.go to keep size smaller |
|
regen
Package regen is a library for generating random strings from regular expressions.
|
Package regen is a library for generating random strings from regular expressions. |
|
test_data
|
|