Documentation
¶
Index ¶
- Constants
- Variables
- func RegisterAltGenNames(key string, alts ...string)
- type Converter
- type Generator
- func (s *Generator) GenHeader(key string, header *spec.Header) (interface{}, error)
- func (s *Generator) GenParameter(key string, param *spec.Parameter) (interface{}, error)
- func (s *Generator) GenResponse(key string, response *spec.Response) (interface{}, error)
- func (s *Generator) GenSchema(key string, schema *spec.Schema) (interface{}, error)
- func (s *Generator) Generate(key string, descriptor interface{}) (interface{}, error)
- type GeneratorOpts
- type StubMode
- type ValueGenerator
Constants ¶
View Source
const ( // XdataGen is the extension tag to be used in specs and hint the stub generator XdataGen = "x-datagen" // StubsDefaultWordCount is the default maximum word count in sentences. It may be overriden with the "words" argument. StubsDefaultWordCount = 10 // StubsDefaultStringLength is the default length for generated strings StubsDefaultStringLength = 30 // StubsDefaultSupplemental defines if "supplemental" words from extra dictionary in faker is enabled StubsDefaultSupplemental = true // StubsDefaultMaxAmount defines the default max amount for prices and other currency amounts StubsDefaultMaxAmount = 1000000 // StubsDefaultMinAmount defines the default min amount for prices and other currency amounts StubsDefaultMinAmount = 100 // StubsDefaultMaxSmallAmount defines the default max amount for small prices and other small currency amounts StubsDefaultMaxSmallAmount = 1000 // StubsDefaultMinSmallAmount defines the default min amount for small prices and other small currency amounts StubsDefaultMinSmallAmount = 10 )
Variables ¶
View Source
var ( // ErrNoValid indicates to the caller that value generator could not abide by validation constraints and generate a valid value ErrNoValid error // ErrNoInvalid indicates to the caller that value generator could not abide by specified invalid mode flags ErrNoInvalid error )
View Source
var ( // Debug is true when the SWAGGER_DEBUG env var is not empty. // It enables a more verbose logging of validators. Debug = os.Getenv("STUBS_DEBUG") != "" )
Functions ¶
func RegisterAltGenNames ¶
RegisterAltGenNames registers alternatives for a generator name
Types ¶
type Generator ¶
type Generator struct {
Language string
}
Generator generates a stub for a descriptor. A descriptor can either be a parameter, response header or json schema
func (*Generator) GenParameter ¶
GenParameter generates a random value for a parameter
func (*Generator) GenResponse ¶
GenResponse generates a random value for a response
type GeneratorOpts ¶
type GeneratorOpts interface {
// FieldName for the value generator, this is mostly used as an alternative to the name
// for inferring which value generator to use
// TODO(fredbi): atm unused
FieldName() string
// Type for the value generator to return, aids in infering the name of the value generator
Type() string
// Format for the value generator to return, aids in infering the name of the value generator
Format() string
// Maximum a numeric value can have, returns value, exclusive, defined
Maximum() (float64, bool, bool)
// Minimum a numeric value can have, returns value, exclusive, defined
Minimum() (float64, bool, bool)
// MaxLength a string can have, returns value, defined
MaxLength() (int64, bool)
// MinLength a string can have, returns value, defined
MinLength() (int64, bool)
// Pattern a string should match, returns value, defined
Pattern() (string, bool)
// MaxItems a collection of values can contain, returns length, defined
MaxItems() (int64, bool)
// MinItems a collection of values must contain, returns length, defined
MinItems() (int64, bool)
// UniqueItems when true the collection can't contain duplicates
UniqueItems() bool
// MultipleOf a numeric value should be divisible by this value, returns value, defined
MultipleOf() (float64, bool)
// Enum a list of acceptable values for a value, returns value, defined
Enum() ([]interface{}, bool)
// Items options for the members of a collection
Items() (GeneratorOpts, error)
// Required when true the property can't be nil
Required() bool
// contains filtered or unexported methods
}
GeneratorOpts interface to capture various types that can get data generated for them.
type StubMode ¶
type StubMode uint64
StubMode for generating data
const ( // Invalid produces a stub which is invalid for a random validation Invalid StubMode = 1 << iota // InvalidRequired produces a stub which is invalid for required InvalidRequired // InvalidMaximum produces a stub which is invalid for maximum InvalidMaximum // InvalidMinimum produces a stub which is invalid for minimum InvalidMinimum // InvalidMaxLength produces a stub which is invalid for max length InvalidMaxLength // InvalidMinLength produces a stub which is invalid for min length InvalidMinLength // InvalidPattern produces a stub which is invalid for pattern InvalidPattern // InvalidMaxItems produces a stub which is invalid for max items InvalidMaxItems // InvalidMinItems produces a stub which is invalid for min items InvalidMinItems // InvalidUniqueItems produces a stub which is invalid for unique items InvalidUniqueItems // InvalidMultipleOf produces a stub which is invalid for multiple of InvalidMultipleOf // InvalidEnum produces a stub which is invalid for enum InvalidEnum // Valid is the default value and generates valid data Valid StubMode = 0 )
type ValueGenerator ¶
type ValueGenerator func(GeneratorOpts) (interface{}, error)
ValueGenerator represents a function to generate a piece of random data
Click to show internal directories.
Click to hide internal directories.