Documentation ¶
Overview ¶
Package ytypes implements YANG type validation logic.
Index ¶
- Constants
- func GetOrCreateNode(schema *yang.Entry, root interface{}, path *gpb.Path) (interface{}, *yang.Entry, error)
- func IsCaseSelected(schema *yang.Entry, value interface{}) (selected []string, errors []error)
- func SetNode(schema *yang.Entry, root interface{}, path *gpb.Path, val interface{}, ...) error
- func StringToType(t reflect.Type, s string) (reflect.Value, error)
- func Unmarshal(schema *yang.Entry, parent interface{}, value interface{}, ...) error
- func Validate(schema *yang.Entry, value interface{}, opts ...ygot.ValidationOption) util.Errors
- func ValidateLeafRefData(schema *yang.Entry, value interface{}, opt *LeafrefOptions) util.Errors
- type Encoding
- type GetHandleWildcards
- type GetNodeOpt
- type GetPartialKeyMatch
- type IgnoreExtraFields
- type InitMissingElements
- type LeafrefOptions
- type Schema
- type SetNodeOpt
- type TreeNode
- type UnmarshalFunc
- type UnmarshalOpt
- type YANGEmpty
Constants ¶
const ( // JSONEncoding indicates that provided value is JSON encoded. JSONEncoding = iota // GNMIEncoding indicates that provided value is gNMI TypedValue. GNMIEncoding )
Variables ¶
This section is empty.
Functions ¶
func GetOrCreateNode ¶ added in v0.6.0
func GetOrCreateNode(schema *yang.Entry, root interface{}, path *gpb.Path) (interface{}, *yang.Entry, error)
GetOrCreateNode function retrieves the node specified by the supplied path from the root which must have the schema supplied. It strictly matches keys in the path, in other words doesn't treat partial match as match. However, if there is no match, a new entry in the map is created. GetOrCreateNode also initializes the nodes along the path if they are nil. Function returns the value and schema of the node as well as error. Note that this function may modify the supplied root even if the function fails.
func IsCaseSelected ¶
IsCaseSelected reports whether a case with the given schema has been selected in the given value struct. The top level of the struct is checked, and any choices present in the schema are recursively followed to determine whether any case is selected for that choice schema subtree. It returns a slice with the names of all fields in the case that were selected.
func SetNode ¶ added in v0.6.0
func SetNode(schema *yang.Entry, root interface{}, path *gpb.Path, val interface{}, opts ...SetNodeOpt) error
SetNode sets the value of the node specified by the supplied path from the specified root, whose schema must also be supplied. It takes a set of options which can be used to specify set behaviours, such as whether or not to ensure that the node's ancestors are initialized.
func StringToType ¶ added in v0.6.0
StringToType converts given string to given type which can be one of the following; - int, int8, int16, int32, int64 - uint, uint8, uint16, uint32, uint64 - string - GoEnum type Function can be extended to support other types as well. If the given string carries an incompatible or overflowing value for the given type, function returns error. Note that castToEnumValue returns (nil, nil) if the given string is carrying an invalid enum string. Function checks not only error, but also value in this case.
func Unmarshal ¶
func Unmarshal(schema *yang.Entry, parent interface{}, value interface{}, opts ...UnmarshalOpt) error
Unmarshal recursively unmarshals JSON data tree in value into the given parent, using the given schema. Any values already in the parent that are not present in value are preserved. If provided schema is a leaf or leaf list, parent must be referencing the parent GoStruct.
func Validate ¶
Validate recursively validates the value of the given data tree struct against the given schema.
func ValidateLeafRefData ¶
func ValidateLeafRefData(schema *yang.Entry, value interface{}, opt *LeafrefOptions) util.Errors
ValidateLeafRefData traverses the entire tree with root value and the given corresponding schema. For the referring node A, the leafref will point to a value set B which may be empty. For each element in B:
- if the element is a leaf, it checks whether A == B
- if the element is a leaf list C, it check whether A is equal to any of the elements of C.
It returns nil if at least one equality check passes or an error otherwise. It also returns an error if any leafref points to a value outside of the tree rooted at value; therefore it should only be called on the root node of the entire data tree. The supplied LeafrefOptions specify particular behaviours of the leafref validation such as ignoring missing pointed to elements.
Types ¶
type Encoding ¶ added in v0.6.0
type Encoding int
Encoding specifies how the value provided to UnmarshalGeneric function is encoded.
type GetHandleWildcards ¶ added in v0.6.0
type GetHandleWildcards struct{}
GetHandleWildcards specifies that a match within GetNode should be allowed to use wildekarts.
func (*GetHandleWildcards) IsGetNodeOpt ¶ added in v0.6.0
func (*GetHandleWildcards) IsGetNodeOpt()
IsGetNodeOpt implements the GetNodeOpt interface.
type GetNodeOpt ¶ added in v0.6.0
type GetNodeOpt interface {
// IsGetNodeOpt is a marker method that is used to identify an instance of GetNodeOpt.
IsGetNodeOpt()
}
GetNodeOpt defines an interface that can be used to supply arguments to functions using GetNode.
type GetPartialKeyMatch ¶ added in v0.6.0
type GetPartialKeyMatch struct{}
GetPartialKeyMatch specifies that a match within GetNode should be allowed to partially match keys for list entries.
func (*GetPartialKeyMatch) IsGetNodeOpt ¶ added in v0.6.0
func (*GetPartialKeyMatch) IsGetNodeOpt()
IsGetNodeOpt implements the GetNodeOpt interface.
type IgnoreExtraFields ¶ added in v0.6.0
type IgnoreExtraFields struct{}
IgnoreExtraFields is an unmarshal option that controls the behaviour of the Unmarshal function when additional fields are found in the input JSON. By default, an error will be returned, by specifying the IgnoreExtraFields option to Unmarshal, extra fields will be discarded.
func (*IgnoreExtraFields) IsUnmarshalOpt ¶ added in v0.6.0
func (*IgnoreExtraFields) IsUnmarshalOpt()
IsUnmarshalOpt marks IgnoreExtraFields as a valid UnmarshalOpt.
type InitMissingElements ¶ added in v0.6.0
type InitMissingElements struct{}
InitMissingElements signals SetNode to initialize the node's ancestors and to ensure that keys are added into keyed lists(maps) if they are missing, before updating the node.
func (*InitMissingElements) IsSetNodeOpt ¶ added in v0.6.0
func (*InitMissingElements) IsSetNodeOpt()
IsSetNodeOpt implements the SetNodeOpt interface.
type LeafrefOptions ¶
type LeafrefOptions struct { // IgnoreMissingData determines whether leafrefs that target a node // that does not exist should return an error to the calling application. When // set to true, no error is returned. // // This functionality is typically used where a partial set of schema information // is populated, but validation is required - for example, configuration for // a protocol within OpenConfig references an interface, but the schema being // validated does not contain the interface definitions. IgnoreMissingData bool // Log specifies whether log entries should be created where a leafref // cannot be successfully resolved. Log bool }
LeafrefOptions controls the behaviour of validation functions for leaf-ref data types.
func (*LeafrefOptions) IsValidationOption ¶
func (*LeafrefOptions) IsValidationOption()
IsValidationOption ensures that LeafrefOptions implements the ValidationOption interface.
type Schema ¶ added in v0.6.0
type Schema struct { Root ygot.ValidatedGoStruct // Root is the ValidatedGoStruct that acts as the root for a schema, it is nil if there is no generated fakeroot. SchemaTree map[string]*yang.Entry // SchemaTree is the extracted schematree for the generated schema. Unmarshal UnmarshalFunc // Unmarshal is a function that can unmarshal RFC7951 JSON into the specified Root type. }
Schema specifies the common types that are part of a generated ygot schema, such that it can be referenced and handled in calling application code.
func (*Schema) IsValid ¶ added in v0.6.0
IsValid determines whether all required fields of the UnmarshalIETFJSON struct have been populated.
func (*Schema) RootSchema ¶ added in v0.6.0
RootSchema returns the YANG entry schema corresponding to the type of the root within the schema.
type SetNodeOpt ¶ added in v0.6.0
type SetNodeOpt interface {
// IsSetNodeOpt is a marker method that is used to identify an instance of SetNodeOpt.
IsSetNodeOpt()
}
SetNodeOpt defines an interface that can be used to supply arguments to functions using SetNode.
type TreeNode ¶ added in v0.6.0
type TreeNode struct { // Schema is the schema entry for the data tree node, specified as a goyang Entry struct. Schema *yang.Entry // Data is the data node found at the path. Data interface{} // Path is the path of the data node that is being returned. Path *gpb.Path }
TreeNode wraps an individual entry within a YANG data tree to return to a caller.
func GetNode ¶ added in v0.6.0
func GetNode(schema *yang.Entry, root interface{}, path *gpb.Path, opts ...GetNodeOpt) ([]*TreeNode, error)
GetNode retrieves the node specified by the supplied path from the specified root, whose schema must also be supplied. It takes a set of options which can be used to specify get behaviours, such as allowing partial match. If there are no matches for the path, an error is returned.
type UnmarshalFunc ¶ added in v0.6.0
type UnmarshalFunc func([]byte, ygot.GoStruct, ...UnmarshalOpt) error
UnmarshalFunc defines a common signature for an RFC7951 to GoStruct unmarshalling function
type UnmarshalOpt ¶ added in v0.6.0
type UnmarshalOpt interface {
IsUnmarshalOpt()
}
UnmarshalOpt is an interface used for any option to be supplied to the Unmarshal function. Types implementing it can be used to control the behaviour of JSON unmarshalling.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package validate is used for testing with the default OpenConfig generated structs.
|
Package validate is used for testing with the default OpenConfig generated structs. |