validators

package
v0.20.0-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2025 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ASCIIOnly

func ASCIIOnly() validator.String

ASCIIOnly returns a string validator which ensures that the string contains only ASCII characters (0-127).

func BlockRequiresSetValue

func BlockRequiresSetValue(setFieldName, requiredValue, blockFieldName string) validator.Object

BlockRequiresSetValue returns an Object validator which ensures that a block can only be specified when a specific value exists in a sibling set field.

func ExactlyOneOf

func ExactlyOneOf(attributeNames ...string) validator.Object

ExactlyOneOf returns a validator that ensures exactly one of the specified attributes is set. This validator works on nested attributes within a block.

func IllegalCharactersInString

func IllegalCharactersInString(forbiddenChars []rune, description string) validator.String

IllegalCharactersInString returns a string validator which ensures that the string does not contain any of the specified forbidden characters.

func JSONSchemaValidator

func JSONSchemaValidator() validator.String

JSONSchemaValidator returns a validator which ensures that a string attribute is a valid JSON and doesn't exceed the maximum allowed nesting depth

func ODataParameterValidator

func ODataParameterValidator(odataFieldNames ...string) validator.String

ODataParameterValidator returns a string validator which ensures that OData parameters are only used with filter_type = "odata" and that at least one OData parameter is provided when filter_type = "odata".

func RegexMatches

func RegexMatches(regexp *regexp.Regexp, message string) validator.String

RegexMatches returns a validator.String that ensures any configured value matches the provided regular expression pattern. Null and unknown values are skipped. An optional message can be provided to customize the error output.

func RequiredWhenEquals

func RequiredWhenEquals(dependentField string, requiredValue types.String) validator.String

RequiredWhenEquals is a factory function that returns a new requiredWhenEqualsValidator. It validates that the attribute is not null or empty when another field in the same object has a specific string value.

func RequiredWhenSetContains

func RequiredWhenSetContains(setFieldName, requiredValue string) validator.String

RequiredWhenSetContains returns a string validator which ensures that the field is required when a sibling set field contains a specific value.

func RequiredWith

func RequiredWith(fieldName string, fieldValue string) validator.String

RequiredWith returns a string validator which ensures that the field is set when another field matches a specific value.

func StringLengthAtMost

func StringLengthAtMost(maxLength int) validator.String

StringLengthAtMost returns a string validator which ensures that the string does not exceed the specified maximum length.

func StringListAllowedValues

func StringListAllowedValues(values ...string) validator.List

StringListAllowedValues returns a validator that ensures each string in a list matches one of the allowed values.

func StringSetAllowedValues

func StringSetAllowedValues(allowedValues ...string) validator.Set

StringSetAllowedValues returns a Set validator which ensures that any configured string set value matches one of the allowed values exactly.

Types

type MutuallyExclusiveAttributesValidator

type MutuallyExclusiveAttributesValidator struct {
	AttributeNames []string
}

MutuallyExclusiveAttributesValidator checks if only one of the specified attributes is set

func (MutuallyExclusiveAttributesValidator) Description

Description returns the validator's description.

func (MutuallyExclusiveAttributesValidator) MarkdownDescription

func (v MutuallyExclusiveAttributesValidator) MarkdownDescription(ctx context.Context) string

MarkdownDescription returns the validator's description in Markdown format.

func (MutuallyExclusiveAttributesValidator) ValidateObject

ValidateObject implements validator logic

Directories

Path Synopsis
graph_beta

Jump to

Keyboard shortcuts

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