Documentation ¶
Index ¶
- Constants
- Variables
- func ApplySchemaConstraints(openAPISchema any, res any) any
- func CastToSchemaFormat(ctx *ReplaceContext, value any) any
- func HasCorrectSchemaValue(ctx *ReplaceContext, value any) bool
- func IsCorrectlyReplacedType(value any, neededType string) bool
- func IsMatchSchemaReadWriteToState(schema *openapi.Schema, state *ReplaceState) bool
- func ReplaceFromContext(ctx *ReplaceContext) any
- func ReplaceFromSchemaExample(ctx *ReplaceContext) any
- func ReplaceFromSchemaFallback(ctx *ReplaceContext) any
- func ReplaceFromSchemaFormat(ctx *ReplaceContext) any
- func ReplaceFromSchemaPrimitive(ctx *ReplaceContext) any
- func ReplaceInHeaders(ctx *ReplaceContext) any
- func ReplaceInPath(ctx *ReplaceContext) any
- func ReplaceValueWithContext(path []string, contextData any) interface{}
- type Any
- type ReplaceContext
- type ReplaceState
- type ReplaceStateOption
- func WithContentType(value string) ReplaceStateOption
- func WithElementIndex(value int) ReplaceStateOption
- func WithHeader() ReplaceStateOption
- func WithName(name string) ReplaceStateOption
- func WithPath() ReplaceStateOption
- func WithReadOnly() ReplaceStateOption
- func WithWriteOnly() ReplaceStateOption
- type Replacer
- type ValueReplacer
Constants ¶
const (
NULL = "__null__"
)
NULL is used to force resolve to nil
Variables ¶
var Replacers = []Replacer{ ReplaceInHeaders, ReplaceInPath, ReplaceFromContext, ReplaceFromSchemaFormat, ReplaceFromSchemaPrimitive, ReplaceFromSchemaExample, ReplaceFromSchemaFallback, }
Replacers is a list of replacers that are used to replace values in schemas and contents in the specified order.
Functions ¶
func ApplySchemaConstraints ¶
ApplySchemaConstraints applies schema constraints to the value. It converts the input value to match the corresponding OpenAPI type specified in the schema.
func CastToSchemaFormat ¶
func CastToSchemaFormat(ctx *ReplaceContext, value any) any
CastToSchemaFormat casts the value to the schema format if possible. If the schema format is not specified, the value is returned as-is.
func HasCorrectSchemaValue ¶
func HasCorrectSchemaValue(ctx *ReplaceContext, value any) bool
HasCorrectSchemaValue checks if the value is of the correct type and format.
func IsCorrectlyReplacedType ¶
IsCorrectlyReplacedType checks if the given value is of the correct schema type.
func IsMatchSchemaReadWriteToState ¶
func IsMatchSchemaReadWriteToState(schema *openapi.Schema, state *ReplaceState) bool
IsMatchSchemaReadWriteToState checks if the given schema is read-write match. ReadOnly - A property that is only available in a response. WriteOnly - A property that is only available in a request.
func ReplaceFromContext ¶
func ReplaceFromContext(ctx *ReplaceContext) any
ReplaceFromContext is a replacer that replaces values from the context.
func ReplaceFromSchemaExample ¶
func ReplaceFromSchemaExample(ctx *ReplaceContext) any
ReplaceFromSchemaExample is a replacer that replaces values from the schema example.
func ReplaceFromSchemaFallback ¶
func ReplaceFromSchemaFallback(ctx *ReplaceContext) any
ReplaceFromSchemaFallback is the last resort to get a value from the schema.
func ReplaceFromSchemaFormat ¶
func ReplaceFromSchemaFormat(ctx *ReplaceContext) any
ReplaceFromSchemaFormat is a replacer that replaces values from the schema format.
func ReplaceFromSchemaPrimitive ¶
func ReplaceFromSchemaPrimitive(ctx *ReplaceContext) any
ReplaceFromSchemaPrimitive is a replacer that replaces values from the schema primitive.
func ReplaceInHeaders ¶
func ReplaceInHeaders(ctx *ReplaceContext) any
ReplaceInHeaders is a replacer that replaces values only in headers.
func ReplaceInPath ¶
func ReplaceInPath(ctx *ReplaceContext) any
ReplaceInPath is a replacer that replaces values only in path parameters.
func ReplaceValueWithContext ¶
ReplaceValueWithContext is a replacer that replaces values from the context.
Types ¶
type ReplaceContext ¶
type ReplaceContext struct { Schema any State *ReplaceState AreaPrefix string Data []map[string]any Faker faker.Faker }
ReplaceContext is a context that is used to replace values in schemas and contents.
Schema is a schema that is used to replace values. Currently only OpenAPI Schema is supported. It does not depend on schema provider as this is already converted to internal Schema type.
State is a state of the current replace operation. It is used to store information about the current element, including its name, index, content type etc.
AreaPrefix is a prefix that is used to identify the correct section in the context config for specific replacement area. e.g. in- then in the contexts we should have: in-header:
X-GeneratedRequest-ID: 123
in-path:
user_id: 123
Data is a list of contexts that are used to replace values. Faker is a faker instance that is used to generate fake data.
type ReplaceState ¶
type ReplaceState struct { NamePath []string ElementIndex int IsHeader bool IsPathParam bool ContentType string IsContentReadOnly bool IsContentWriteOnly bool // contains filtered or unexported fields }
ReplaceState is a struct that holds information about the current state of the replace operation.
NamePath is a slice of names of the current element. It is used to build a path to the current element. For example, "users", "name", "first".
ElementIndex is an index of the current element if required structure to generate is an array. IsHeader is a flag that indicates that the current element we're replacing is a header. IsPathParam is a flag that indicates that the current element we're replacing is a path parameter. ContentType is a content type of the current element. IsContentReadOnly is a flag that indicates that the current element we're replacing is a read-only content. This value is used only when Scheme has ReadOnly set to true.
IsContentWriteOnly is a flag that indicates that the current element we're replacing is a write-only content. This value is used only when Scheme has WriteOnly set to true.
func NewReplaceState ¶
func NewReplaceState(opts ...ReplaceStateOption) *ReplaceState
func NewReplaceStateWithName ¶
func NewReplaceStateWithName(name string) *ReplaceState
func (*ReplaceState) NewFrom ¶
func (s *ReplaceState) NewFrom(src *ReplaceState) *ReplaceState
NewFrom creates a new ReplaceState instance from the given one.
func (*ReplaceState) WithOptions ¶
func (s *ReplaceState) WithOptions(options ...ReplaceStateOption) *ReplaceState
type ReplaceStateOption ¶
type ReplaceStateOption func(*ReplaceState)
func WithContentType ¶
func WithContentType(value string) ReplaceStateOption
func WithElementIndex ¶
func WithElementIndex(value int) ReplaceStateOption
func WithHeader ¶
func WithHeader() ReplaceStateOption
func WithName ¶
func WithName(name string) ReplaceStateOption
func WithPath ¶
func WithPath() ReplaceStateOption
func WithReadOnly ¶
func WithReadOnly() ReplaceStateOption
func WithWriteOnly ¶
func WithWriteOnly() ReplaceStateOption
type Replacer ¶
type Replacer func(ctx *ReplaceContext) any
Replacer is a function that returns a value to replace the original value with. Replacer functions are predefined and set in the correct order to be executed.
type ValueReplacer ¶
type ValueReplacer func(schemaOrContent any, state *ReplaceState) any
ValueReplacer is a function that replaces value in schema or content. This function should encapsulate all the logic, data, contexts etc. of replacing values.
func CreateValueReplacer ¶
func CreateValueReplacer(cfg *config.Config, replacers []Replacer, contexts []map[string]any) ValueReplacer
CreateValueReplacer is a factory that creates a new ValueReplacer instance from the given config and contexts.