constraint
ballerina/constraint Ballerina library
Overview
This module provides features to validate the values that have been assigned to Ballerina types.
The Ballerina constraint
module facilitates APIs to do validations on the Ballerina types further with the use of annotations.
Functions
validate
function validate(anydata value, typedesc<anydata> td) returns td|Error
Validates the provided value against the configured annotations. Additionally, if the type of the value is different from the expected return type then the value will be cloned with the contextually expected type before the validation.
Parameters
- value anydata - The
anydata
type value to be constrained
- td typedesc<anydata> (default <>) - The type descriptor of the value to be constrained
Return Type
- td|Error - The type descriptor of the value which is validated or else an
constraint:Error
in case of an error
Enums
constraint: DateOption
Represents the date option to be validated.
Members
Annotations
constraint: Array
The annotation, which is used for the constraints of the anydata[]
type.
constraint: Date
The annotation, which is used for the constraints of the Date
type, which is structurally equivalent
to the following record:
type Date record { int year; int month; int day; };
This annotation will enable validation on the date fields in the record. Additionally,
the option
field can be used to validate the date against the provided option.
constraint: Float
The annotation, which is used for the constraints of the float
type.
constraint: Int
The annotation, which is used for the constraints of the int
type.
constraint: Number
The annotation, which is used for the constraints of the int
, float
, and decimal
types.
constraint: String
The annotation, which is used for the constraints of the string
type.
Records
constraint: ArrayConstraints
Represents the constraints associated with anydata[]
type.
Fields
constraint: ConstraintRecord
Represents the constraint details as a record.
Fields
- value anydata - The value for the constraint
- message string - The message to be returned in case of the constraint violation
constraint: DateConstraints
Represents the constraints associated with Date
type.
Fields
- option DateOption|record {| value DateOption |}? - date option to be validated
- message string? - The message to be returned in case of the constraint violation
constraint: FloatConstraints
Represents the constraints associated with float
type.
Fields
constraint: IntConstraints
Represents the constraints associated with int
type.
Fields
constraint: NumberConstraints
Represents the constraints associated with int
, float
and decimal
types.
Fields
constraint: StringConstraints
Represents the constraints associated with string
type.
Fields
Errors
Import
import ballerina/constraint;
Metadata
Released date: 11 months ago
Version: 1.5.0
License: Apache-2.0
Compatibility
Platform: java17
Ballerina version: 2201.8.0
GraalVM compatible: Yes
Pull count
Total: 473683
Current verison: 96490
Weekly downloads
Keywords
constraint
validation
Contributors