twitter / finatra

Fast, testable, Scala services built on TwitterServer and Finagle
https://twitter.github.io/finatra/
Apache License 2.0
2.27k stars 410 forks source link

added @Pattern annotation to finatra/jackson for regex based string v… #481

Closed mesut closed 5 years ago

mesut commented 5 years ago

finatra-jackson: added @Pattern annotation for regex based string validation

Problem

We should able to validate http request parameters whether match the given regex pattern. For instance, Finatra should able to validate phone parameter whether matches to phone pattern.

case class MyRequest(phone: String)

Solution

Added @Patternannotation to finatra-jackson for regex based validation. If the regex do not match, it will return PatternNotMatches errorCode which contains the regex and value

Result With @Pattern annotation we provide regex that checks the parameter match or not.

case class MyRequest( @Pattern(regexp= "^[+][(]{0,1}[0-9]{1,4}[)]{0,1}[-\s./0-9]$") phone: String)

CLAassistant commented 5 years ago

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Mesut OZEN seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

codecov[bot] commented 5 years ago

Codecov Report

Merging #481 into develop will decrease coverage by <.01%. The diff coverage is 88.46%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #481      +/-   ##
===========================================
- Coverage    92.64%   92.64%   -0.01%     
===========================================
  Files          240      241       +1     
  Lines         3835     3861      +26     
  Branches       304      304              
===========================================
+ Hits          3553     3577      +24     
- Misses         282      284       +2
Impacted Files Coverage Δ
...class/validation/validators/PatternValidator.scala 88.46% <88.46%> (ø)
...finatra/validation/ValidationMessageResolver.scala 91.66% <0%> (+8.33%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update d3f833a...c4a6460. Read the comment docs.

mesut commented 5 years ago

cla problem