Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to overwrite default error message #79

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
org = "ballerina"
name = "constraint"
version = "1.2.0"
version = "1.2.1"
authors = ["Ballerina"]
keywords = ["constraint", "validation"]
repository = "https://github.com/ballerina-platform/module-ballerina-constraint"
Expand All @@ -12,5 +12,5 @@ distribution = "2201.5.0"
[[platform.java11.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "constraint-native"
version = "1.2.0"
path = "../native/build/libs/constraint-native-1.2.0.jar"
version = "1.2.1"
path = "../native/build/libs/constraint-native-1.2.1-SNAPSHOT.jar"
2 changes: 1 addition & 1 deletion ballerina/CompilerPlugin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ id = "constraint-compiler-plugin"
class = "io.ballerina.stdlib.constraint.compiler.ConstraintCompilerPlugin"

[[dependency]]
path = "../compiler-plugin/build/libs/constraint-compiler-plugin-1.2.0.jar"
path = "../compiler-plugin/build/libs/constraint-compiler-plugin-1.2.1-SNAPSHOT.jar"
4 changes: 2 additions & 2 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ distribution-version = "2201.5.0"
[[package]]
org = "ballerina"
name = "constraint"
version = "1.2.0"
version = "1.2.1"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "test"},
Expand Down Expand Up @@ -43,7 +43,7 @@ modules = [
[[package]]
org = "ballerina"
name = "time"
version = "2.2.4"
version = "2.2.5"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
Expand Down
51 changes: 31 additions & 20 deletions ballerina/constraint.bal
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,26 @@ type DateRecord record {
int day;
};

# Represents the constraint details as a record.
#
# + value - The value for the constraint
# + message - The message to be returned in case of the constraint violation
public type ConstraintRecord record {|
anydata value;
string message;
|};

# Represents the constraints associated with `int` type.
#
# + minValue - The inclusive lower bound of the constrained type
# + maxValue - The inclusive upper bound of the constrained type
# + minValueExclusive - The exclusive lower bound of the constrained type
# + maxValueExclusive - The exclusive upper bound of the constrained type
public type IntConstraints record {|
int minValue?;
int maxValue?;
int minValueExclusive?;
int maxValueExclusive?;
int|record{| *ConstraintRecord; int value; |} minValue?;
int|record{| *ConstraintRecord; int value; |} maxValue?;
int|record{| *ConstraintRecord; int value; |} minValueExclusive?;
int|record{| *ConstraintRecord; int value; |} maxValueExclusive?;
|};

# Represents the constraints associated with `float` type.
Expand All @@ -72,10 +81,10 @@ public type IntConstraints record {|
# + minValueExclusive - The exclusive lower bound of the constrained type
# + maxValueExclusive - The exclusive upper bound of the constrained type
public type FloatConstraints record {|
float minValue?;
float maxValue?;
float minValueExclusive?;
float maxValueExclusive?;
float|record{| *ConstraintRecord; float value; |} minValue?;
float|record{| *ConstraintRecord; float value; |} maxValue?;
float|record{| *ConstraintRecord; float value; |} minValueExclusive?;
float|record{| *ConstraintRecord; float value; |} maxValueExclusive?;
|};

# Represents the constraints associated with `int`, `float` and `decimal` types.
Expand All @@ -85,10 +94,10 @@ public type FloatConstraints record {|
# + minValueExclusive - The exclusive lower bound of the constrained type
# + maxValueExclusive - The exclusive upper bound of the constrained type
public type NumberConstraints record {|
decimal minValue?;
decimal maxValue?;
decimal minValueExclusive?;
decimal maxValueExclusive?;
decimal|record{| *ConstraintRecord; decimal value; |} minValue?;
decimal|record{| *ConstraintRecord; decimal value; |} maxValue?;
decimal|record{| *ConstraintRecord; decimal value; |} minValueExclusive?;
decimal|record{| *ConstraintRecord; decimal value; |} maxValueExclusive?;
|};

# Represents the constraints associated with `string` type.
Expand All @@ -98,10 +107,10 @@ public type NumberConstraints record {|
# + maxLength - The inclusive upper bound of the number of characters of the constrained `string` type
# + pattern - The regular expression to be matched with the constrained `string` type
public type StringConstraints record {|
int length?;
int minLength?;
int maxLength?;
string:RegExp pattern?;
int|record{| *ConstraintRecord; int value; |} length?;
int|record{| *ConstraintRecord; int value; |} minLength?;
int|record{| *ConstraintRecord; int value; |} maxLength?;
string:RegExp|record{| *ConstraintRecord; string:RegExp value; |} pattern?;
|};

# Represents the constraints associated with `anydata[]` type.
Expand All @@ -110,9 +119,9 @@ public type StringConstraints record {|
# + minLength - The inclusive lower bound of the number of members of the constrained type
# + maxLength - The inclusive upper bound of the number of members of the constrained type
public type ArrayConstraints record {|
int length?;
int minLength?;
int maxLength?;
int|record{| *ConstraintRecord; int value; |} length?;
int|record{| *ConstraintRecord; int value; |} minLength?;
int|record{| *ConstraintRecord; int value; |} maxLength?;
|};

# Represents the date option to be validated.
Expand All @@ -130,8 +139,10 @@ public enum DateOption {
# Represents the constraints associated with `Date` type.
#
# + option - date option to be validated
# + message - The message to be returned in case of the constraint violation
public type DateConstraints record {
DateOption option?;
DateOption|record{| *ConstraintRecord; DateOption value; |} option?;
string message?;
};

# Validates the provided value against the configured annotations. Additionally, if the type of the value is different
Expand Down
Loading