defaulting

package
v0.32.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2024 License: Apache-2.0 Imports: 14 Imported by: 16

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Default

func Default(x interface{}, s *structuralschema.Structural)

Default does defaulting of x depending on default values in s. Default values from s are deep-copied.

PruneNonNullableNullsWithoutDefaults has left the non-nullable nulls that have a default here.

func PruneDefaults added in v0.16.4

func PruneDefaults(s *structuralschema.Structural) error

PruneDefaults prunes default values according to the schema and according to the ObjectMeta definition of the running server. It mutates the passed schema.

func PruneNonNullableNullsWithoutDefaults added in v0.20.0

func PruneNonNullableNullsWithoutDefaults(x interface{}, s *structuralschema.Structural)

PruneNonNullableNullsWithoutDefaults removes non-nullable non-defaultable null values from object.

Non-nullable nulls that have a default are left alone here and will be defaulted later.

func ValidateDefaults added in v0.16.4

func ValidateDefaults(ctx context.Context, pth *field.Path, s *structuralschema.Structural, isResourceRoot, requirePrunedDefaults bool) (field.ErrorList, error)

ValidateDefaults checks that default values validate and are properly pruned. context is passed for supporting context cancellation during cel validation

Types

type AccessorFunc added in v0.16.4

type AccessorFunc func(obj map[string]interface{}) (x interface{}, found bool, err error)

AccessorFunc returns a node x in obj on a fixed (implicitly encoded) JSON path if that path exists in obj (found==true). If it does not exist, found is false. If on the path the type of a field is wrong, an error is returned.

type SurroundingObjectFunc added in v0.16.4

type SurroundingObjectFunc func(focus interface{}) (map[string]interface{}, AccessorFunc, error)

SurroundingObjectFunc is a surrounding object builder with a given x at a leaf. Which leave is determined by the series of Index() and Child(k) calls. It also returns the inverse of the builder, namely the accessor that extracts x from the test object.

With obj, acc, _ := someSurroundingObjectFunc(x) we get:

acc(obj) == x
reflect.DeepEqual(acc(DeepCopy(obj), x) == x

where x is the original instance for slices and maps.

If after computation of acc the node holding x in obj is mutated (e.g. pruned), the accessor will return that mutated node value (e.g. the pruned x).

Example (ignoring the last two return values):

NewRootObjectFunc()(x) == x
NewRootObjectFunc().Index()(x) == [x]
NewRootObjectFunc().Index().Child("foo") == [{"foo": x}]
NewRootObjectFunc().Index().Child("foo").Child("bar") == [{"foo": {"bar":x}}]
NewRootObjectFunc().Index().Child("foo").Child("bar").Index() == [{"foo": {"bar":[x]}}]

and:

NewRootObjectFunc(), then acc(x) == x
NewRootObjectFunc().Index(), then acc([x]) == x
NewRootObjectFunc().Index().Child("foo"), then acc([{"foo": x}]) == x
NewRootObjectFunc().Index().Child("foo").Child("bar"), then acc([{"foo": {"bar":x}}]) == x
NewRootObjectFunc().Index().Child("foo").Child("bar").Index(), then acc([{"foo": {"bar":[x]}}]) == x

func NewRootObjectFunc added in v0.16.4

func NewRootObjectFunc() SurroundingObjectFunc

NewRootObjectFunc returns the identity function. The passed focus value must be an object.

func (SurroundingObjectFunc) Child added in v0.16.4

Child returns a function x => f({k: x}) and the corresponding accessor.

func (SurroundingObjectFunc) Index added in v0.16.4

Index returns a function x => f([x]) and the corresponding accessor.

func (SurroundingObjectFunc) WithTypeMeta added in v0.16.4

WithTypeMeta returns a closure with the TypeMeta fields set if they are defined. This mutates f(x).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL