constraint
Module 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.
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
Annotations
constraint: Array
The annotation, which is used for the constraints of the anydata[]
type.
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
- length int? - The number of members of the constrained type
- minLength int? - The inclusive lower bound of the number of members of the constrained type
- maxLength int? - The inclusive upper bound of the number of members of the constrained type
constraint: FloatConstraints
Represents the constraints associated with float
type.
Fields
- minValue float? - The inclusive lower bound of the constrained type
- maxValue float? - The inclusive upper bound of the constrained type
- minValueExclusive float? - The exclusive lower bound of the constrained type
- maxValueExclusive float? - The exclusive upper bound of the constrained type
constraint: IntConstraints
Represents the constraints associated with int
type.
Fields
- minValue int? - The inclusive lower bound of the constrained type
- maxValue int? - The inclusive upper bound of the constrained type
- minValueExclusive int? - The exclusive lower bound of the constrained type
- maxValueExclusive int? - The exclusive upper bound of the constrained type
constraint: NumberConstraints
Represents the constraints associated with int
, float
and decimal
types.
Fields
- minValue decimal? - The inclusive lower bound of the constrained type
- maxValue decimal? - The inclusive upper bound of the constrained type
- minValueExclusive decimal? - The exclusive lower bound of the constrained type
- maxValueExclusive decimal? - The exclusive upper bound of the constrained type
constraint: StringConstraints
Represents the constraints associated with string
type.
Fields
- length int? - The number of characters of the constrained
string
type
- minLength int? - The inclusive lower bound of the number of characters of the constrained
string
type
- maxLength int? - The inclusive upper bound of the number of characters of the constrained
string
type
Errors
constraint: Error
Represents the error type of the module.
Import
import ballerina/constraint;
Metadata
Released date: almost 2 years ago
Version: 1.0.1
License: Apache-2.0
Compatibility
Platform: java11
Ballerina version: 2201.2.0
GraalVM compatible: Yes
Pull count
Total: 484342
Current verison: 46759
Weekly downloads
Keywords
constraint
validation
Contributors