Documentation
¶
Index ¶
- func AllowedIfDependentPathEquals(dependentPath path.Path, requiredValue string) condition
- func AllowedIfDependentPathOneOf(dependentPath path.Path, allowedValues []string) condition
- func DependantPathOneOf(dependentPath path.Path, allowedValues []string) condition
- func ForbiddenIfDependentPathOneOf(dependentPath path.Path, allowedValues []string) condition
- func IsUUID() validator.String
- func RequiredIfDependentPathEquals(dependentPath path.Path, requiredValue string) condition
- func RequiredIfDependentPathOneOf(dependentPath path.Path, allowedValues []string) condition
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllowedIfDependentPathEquals ¶ added in v0.11.19
AllowedIfDependentPathEquals returns a condition that allows a field to be set only if the value at the specified dependent path equals the required value. This is a convenience function that wraps AllowedIfDependentPathOneOf with a single value slice.
Parameters:
- dependentPath: The path to the field whose value determines if this field is allowed
- requiredValue: The exact string value that the dependent field must equal
Returns:
- condition: A validation condition that enforces the dependency rule
func AllowedIfDependentPathOneOf ¶ added in v0.11.19
AllowedIfDependentPathOneOf creates a validation condition that allows the current attribute to be set only when a dependent attribute at the specified path has one of the allowed values.
Parameters:
- dependentPath: The path to the attribute that this validation depends on
- allowedValues: A slice of string values that the dependent attribute must match
Returns:
- condition: A validation condition that can be used with conditional validators
Example:
// Only allow "ssl_cert" to be set when "protocol" is "https"
AllowedIfDependentPathOneOf(path.Root("protocol"), []string{"https"})
func DependantPathOneOf ¶ added in v0.11.19
DependantPathOneOf creates a condition that validates a dependent path's value is one of the allowed values. It returns a condition that checks if the value at dependentPath matches any of the provided allowedValues. If the dependent field does not have an allowed value, it generates a diagnostic error indicating which values are permitted and what the current value is.
Parameters:
- dependentPath: The path to the attribute that must have one of the allowed values
- allowedValues: A slice of strings representing the valid values for the dependent path
Returns:
- condition: A condition struct that can be used for validation
func ForbiddenIfDependentPathOneOf ¶ added in v0.11.19
ForbiddenIfDependentPathOneOf creates a validation condition that forbids setting a value when a dependent field matches one of the specified allowed values.
This validator is useful for creating mutually exclusive configuration scenarios where certain attributes should not be set when another attribute has specific values.
Parameters:
- dependentPath: The path to the field whose value determines the validation behavior
- allowedValues: A slice of string values that, when matched by the dependent field, will trigger the forbidden condition
Returns:
- condition: A validation condition that will generate an error if the current field is set while the dependent field matches any of the allowed values
Example usage:
validator := ForbiddenIfDependentPathOneOf(
path.Root("type"),
[]string{"basic", "simple"},
)
// This will prevent setting the current attribute when "type" equals "basic" or "simple"
func RequiredIfDependentPathEquals ¶ added in v0.11.19
RequiredIfDependentPathEquals returns a condition that makes a field required when the value at the specified dependent path equals the given required value. This is a convenience function that wraps RequiredIfDependentPathOneOf with a single value slice.
Parameters:
- dependentPath: The path to the field whose value will be checked
- requiredValue: The value that, when present at dependentPath, makes this field required
Returns:
- condition: A validation condition function
func RequiredIfDependentPathOneOf ¶ added in v0.11.19
RequiredIfDependentPathOneOf returns a condition that validates an attribute is required when a dependent attribute's value matches one of the specified allowed values.
The condition checks if the dependent attribute (specified by dependentPath) has a value that is present in the allowedValues slice. If the dependent attribute matches any of the allowed values, then the attribute being validated must not be null or unknown.
Parameters:
- dependentPath: The path to the attribute whose value determines the requirement
- allowedValues: A slice of string values that trigger the requirement when matched
Returns:
- condition: A validation condition that enforces the requirement rule
Example usage:
validator := RequiredIfDependentPathOneOf(
path.Root("type"),
[]string{"custom", "advanced"},
)
// This would require the current attribute when "type" equals "custom" or "advanced"
Types ¶
This section is empty.