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 @pattern support for constraint package #29

Merged
merged 14 commits into from
Jan 17, 2023

Conversation

TharmiganK
Copy link
Contributor

@TharmiganK TharmiganK commented Nov 2, 2022

Purpose

$Subject

Fixes : Add @pattern support for constraint package #3179

Examples

import ballerina/log;
import ballerina/constraint;

string:RegExp regExp = re `([0-9]{10})|(\+[0-9]{11})`;

@constraint:String {pattern: regExp}
type PhoneNumber string;

type User record {|
    string name;
    @constraint:String {pattern: re `male|female`}
    string gender?;
    int age;
    @constraint:String {pattern: re `([0-9]{9}[v|V]|[0-9]{12})`}
    string nic;
|};

type UserAdvanced record {|
    *User;
    PhoneNumber contactNumber;
    @constraint:String {pattern: re `([a-zA-Z0-9._%\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,6})*`}
    string email;
|};

public function main() {
    PhoneNumber phoneNumber = "0774563957";
    do {
        phoneNumber = check constraint:validate(phoneNumber);
        log:printInfo("phone number is valid");
    } on fail error err {
        log:printError("error occurred while checking phone number", err);
    }

    User user = {
        name: "John",
        age: 36,
        gender: "male",
        nic: "198654673682"
    };
    do {
        user = check constraint:validate(user);
        log:printInfo("user is valid");
    } on fail error err {
        log:printError("error occurred while checking user", err);
    }

    UserAdvanced userAdvanced = {
        ... user,
        contactNumber: phoneNumber,
        email: "[email protected]"
    };
    do {
        userAdvanced = check constraint:validate(userAdvanced);
        log:printInfo("userAdvanced is valid");
    } on fail error err {
        log:printError("error occurred while checking userAdvanced", err);
    }
}

Checklist

  • Linked to an issue
  • Updated the changelog
  • Added tests
  • Updated the spec
  • Checked native-image compatibility

@codecov
Copy link

codecov bot commented Nov 2, 2022

Codecov Report

Base: 89.51% // Head: 90.11% // Increases project coverage by +0.60% 🎉

Coverage data is based on head (5352f0c) compared to base (ecce026).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@             Coverage Diff              @@
##               main      #29      +/-   ##
============================================
+ Coverage     89.51%   90.11%   +0.60%     
- Complexity      121      126       +5     
============================================
  Files            17       18       +1     
  Lines           248      253       +5     
  Branches         43       43              
============================================
+ Hits            222      228       +6     
  Misses           13       13              
+ Partials         13       12       -1     
Impacted Files Coverage Δ
ballerina/constraint.bal 100.00% <ø> (ø)
...java/io/ballerina/stdlib/constraint/Constants.java 0.00% <ø> (ø)
...stdlib/constraint/InternalValidationException.java 100.00% <ø> (ø)
...onstraint/validators/ArrayConstraintValidator.java 100.00% <100.00%> (ø)
...onstraint/validators/FloatConstraintValidator.java 100.00% <100.00%> (ø)
.../constraint/validators/IntConstraintValidator.java 100.00% <100.00%> (ø)
...nstraint/validators/NumberConstraintValidator.java 100.00% <100.00%> (ø)
...nstraint/validators/StringConstraintValidator.java 100.00% <100.00%> (ø)
...straint/validators/interfaces/LengthValidator.java 100.00% <100.00%> (ø)
...traint/validators/interfaces/PatternValidator.java 100.00% <100.00%> (ø)
... and 1 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@TharmiganK TharmiganK marked this pull request as ready for review November 2, 2022 06:53
@TharmiganK TharmiganK requested a review from chamil321 November 3, 2022 07:03
@TharmiganK TharmiganK marked this pull request as draft November 18, 2022 04:51
@github-actions

This comment was marked as outdated.

@github-actions github-actions bot added the Stale label Dec 3, 2022
@TharmiganK TharmiganK removed the Stale label Dec 4, 2022
@github-actions

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

@github-actions github-actions bot added the Stale label Jan 4, 2023
@TharmiganK TharmiganK removed the Stale label Jan 5, 2023
# Conflicts:
#	ballerina/Ballerina.toml
#	build-config/resources/Ballerina.toml
#	changelog.md
#	gradle.properties
#	native/src/main/java/io/ballerina/stdlib/constraint/validators/AbstractLengthValidator.java
@TharmiganK TharmiganK marked this pull request as ready for review January 10, 2023 03:55
@shafreenAnfar
Copy link
Contributor

Didn't go through the code but the functionality looks good to me!

Hope @chamil321 will validate the tests and the code. Also lets make sure tooling side is ready when it comes to regex.

@TharmiganK
Copy link
Contributor Author

Didn't go through the code but the functionality looks good to me!

Hope @chamil321 will validate the tests and the code. Also lets make sure tooling side is ready when it comes to regex.

There are still some pending issues regarding the tooling support for regexp from lang side such as :

@TharmiganK TharmiganK merged commit c28d998 into ballerina-platform:main Jan 17, 2023
@TharmiganK TharmiganK deleted the add-pattern-support branch January 31, 2023 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add @pattern support for constraint package
3 participants