Documentation ¶
Index ¶
- func RegisterAltGenNames(key string, alts ...string)
- 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) 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 ¶
This section is empty.
Variables ¶
This section is empty.
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
type GeneratorOpts ¶
type GeneratorOpts interface { // value generator name Name() string // Args for the value generator (eg. number of words in a sentence) // Arguments here are used to generate a valid value when no validations are specified. // Args are used as default setting but validations can override the args should that be necessary. Args() []interface{} // FieldName for the value generator, this is mostly used as an alternative to the name // for inferring which value generator to use FieldName() string // Type for the value generator to return, adids in inferring the name of the value generator Type() string // Format for the value generator to return, aids in inferring the name of the value generator Format() string // Mode which kind of random data to return and to indicate which validation(s) should fail. // This is a bitmask so it allows for combinations of invalid values. Mode() StubMode // 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 }
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.