Skip to content

Commit

Permalink
Ajustes IsOptional
Browse files Browse the repository at this point in the history
  • Loading branch information
dliocode committed Nov 16, 2022
1 parent 05cfd1d commit 50d90b6
Show file tree
Hide file tree
Showing 17 changed files with 229 additions and 437 deletions.
2 changes: 1 addition & 1 deletion DataValidator.delphilsp.json

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions DataValidator.dpk
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,24 @@ package DataValidator;
{$EXTENDEDSYNTAX ON}
{$IMPORTEDDATA ON}
{$IOCHECKS ON}
{$LOCALSYMBOLS ON}
{$LOCALSYMBOLS OFF}
{$LONGSTRINGS ON}
{$OPENSTRINGS ON}
{$OPTIMIZATION OFF}
{$OPTIMIZATION ON}
{$OVERFLOWCHECKS OFF}
{$RANGECHECKS OFF}
{$REFERENCEINFO ON}
{$REFERENCEINFO OFF}
{$SAFEDIVIDE OFF}
{$STACKFRAMES ON}
{$STACKFRAMES OFF}
{$TYPEDADDRESS OFF}
{$VARSTRINGCHECKS ON}
{$WRITEABLECONST OFF}
{$MINENUMSIZE 1}
{$IMAGEBASE $400000}
{$DEFINE DEBUG}
{$DEFINE RELEASE}
{$ENDIF IMPLICITBUILDING}
{$IMPLICITBUILD ON}
{$RUNONLY}
{$IMPLICITBUILD OFF}

requires
rtl;
Expand Down
393 changes: 75 additions & 318 deletions DataValidator.dproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion samples/JSON/Basic/Basic.delphilsp.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion samples/JSON/Basic/Basic.dproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{003881DF-B1A2-46DF-906B-76CFCE2C63D1}</ProjectGuid>
<ProjectVersion>19.4</ProjectVersion>
<ProjectVersion>19.5</ProjectVersion>
<FrameworkType>VCL</FrameworkType>
<Base>True</Base>
<Config Condition="'$(Config)'==''">Debug</Config>
Expand Down
9 changes: 0 additions & 9 deletions samples/JSON/Basic/UBasic.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ object Form2: TForm2
Color = 2565927
ParentBackground = False
TabOrder = 0
ExplicitHeight = 757
object btnLimpar: TButton
AlignWithMargins = True
Left = 3
Expand Down Expand Up @@ -80,8 +79,6 @@ object Form2: TForm2
Align = alClient
BevelOuter = bvNone
TabOrder = 1
ExplicitWidth = 1244
ExplicitHeight = 757
object PageControl1: TPageControl
Left = 0
Top = 0
Expand Down Expand Up @@ -117,9 +114,6 @@ object Form2: TForm2
Color = clCream
ScrollBars = ssBoth
TabOrder = 1
ExplicitLeft = 600
ExplicitWidth = 143
ExplicitHeight = 603
end
end
object TabSample2: TTabSheet
Expand Down Expand Up @@ -180,9 +174,6 @@ object Form2: TForm2
Color = clCream
ScrollBars = ssBoth
TabOrder = 1
ExplicitLeft = 600
ExplicitWidth = 636
ExplicitHeight = 727
end
end
end
Expand Down
139 changes: 72 additions & 67 deletions samples/JSON/Basic/UBasic.pas
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,11 @@ function TForm2.ValidationTab2: IDataValidatorJSONResult;

.Value
.Trim
.&Not.IsEmpty.WithMessage('O ${key} deve ser informado!')
.IsOptional(
function(const AValue: TJSONValue): Boolean
begin
Result := AValue.Null;
end)
.IsJSONString.WithMessage('${key} - ${value} - Não é do tipo string!')
.IsLength(10,10).WithMessage('${key} - Deve ter somente 10 caracteres!')
.IsDate(False).WithMessage('${key} - ${value} - Não é uma data válida!')
Expand Down Expand Up @@ -375,84 +379,85 @@ function TForm2.ValidationTab2: IDataValidatorJSONResult;
.IsEmail.WithMessage('${key} - ${value} - Não é um e-mail válido!')
.&End
.&End
;

.Validate('items')
.Key
.IsRequired.WithMessage('Informe a key ${key}')
.&End
LResult := LJSONResult.Check;

.Value
.IsJSONObject.WithMessage('${key} - Não é do tipo JSONObject!')
.CustomJSONSubValidator(
function(const AValue: IDataValidatorJSON; var AMessage: TDataValidatorMessage): Boolean
var
LJSONResult: IDataValidatorJSONResult;
LResult: IDataValidatorResult;
begin
LJSONResult :=
AValue
.Validate('product_id')
.Key
.IsRequired.WithMessage('Informe a key ${key}')
.&End
Result := LResult.OK;

.Value
.Trim
.&Not.IsEmpty.WithMessage('O ${key} deve ser informado!')
.IsJSONNumeric.WithMessage('${key} - ${value} - Não é do tipo numeric!')
.IsGreaterThan(0).WithMessage('O ${key} deve ser maior que zero!')
.IsInteger.WithMessage('O ${key} deve ser do tipo inteiro!')
.&End
.&End
if not Result then
AMessage := LResult.Informations.GetItem(0).Messages;
end)

.Validate('product_name')
.Key
.IsRequired.WithMessage('Informe a key ${key}')
.&End
.&End
.&End

.Value
.Trim
.&Not.IsEmpty.WithMessage('O ${key} deve ser informado!')
.IsJSONString.WithMessage('${key} - ${value} - Não é do tipo string!')
.IsAlphaNumeric(TDataValidatorLocaleLanguage.tl_pt_BR, ['-', ',', '/', '\']).WithMessage('${key} - ${value} - Não é um valor AlphaNumeric!')
.&End
.&End
.Validate('items')
.Key
.IsRequired.WithMessage('Informe a key ${key}')
.&End

.Validate('price')
.Key
.IsRequired.WithMessage('Informe a key ${key}')
.&End
.Value
.IsJSONArray.WithMessage('${key} - Não é do tipo JSONArray!')
.CustomJSONSubValidator(
function(const AValue: IDataValidatorJSON; var AMessage: TDataValidatorMessage): Boolean
var
LJSONResult: IDataValidatorJSONResult;
LResult: IDataValidatorResult;
begin
LJSONResult :=
AValue
.Validate('product_id')
.Key
.IsRequired.WithMessage('Informe a key ${key}')
.&End

.Value
.Trim
.&Not.IsEmpty.WithMessage('O ${key} deve ser informado!')
.IsNumeric.WithMessage('O ${key} não é um valor inválido!')
.IsGreaterThan(-1).WithMessage('Informe um valor maior que Zero!')
.&End
.&End
.Value
.Trim
.&Not.IsEmpty.WithMessage('O ${key} deve ser informado!')
.IsJSONNumeric.WithMessage('${key} - ${value} - Não é do tipo numeric!')
.IsGreaterThan(0).WithMessage('O ${key} deve ser maior que zero!')
.IsInteger.WithMessage('O ${key} deve ser do tipo inteiro!')
.&End
.&End

.Validate('quantity')
.Key
.IsRequired.WithMessage('Informe a key ${key}')
.&End
.Validate('product_name')
.Key
.IsRequired.WithMessage('Informe a key ${key}')
.&End

.Value
.Trim
.&Not.IsEmpty.WithMessage('O ${key} deve ser informado!')
.IsNumeric.WithMessage('O ${key} não é um valor inválido!')
.&End
.&End
;
.Value
.Trim
.&Not.IsEmpty.WithMessage('O ${key} deve ser informado!')
.IsJSONString.WithMessage('${key} - ${value} - Não é do tipo string!')
.IsAlphaNumeric(TDataValidatorLocaleLanguage.tl_pt_BR, ['-', ',', '/', '\']).WithMessage('${key} - ${value} - Não é um valor AlphaNumeric!')
.&End
.&End

LResult := LJSONResult.Check;
.Validate('price')
.Key
.IsRequired.WithMessage('Informe a key ${key}')
.&End

Result := LResult.OK;
.Value
.Trim
.&Not.IsEmpty.WithMessage('O ${key} deve ser informado!')
.IsNumeric.WithMessage('O ${key} não é um valor inválido!')
.IsGreaterThan(-1).WithMessage('Informe um valor maior que Zero!')
.&End
.&End

if not Result then
AMessage := LResult.Informations.GetItem(0).Messages;
end)
.&End
.Validate('quantity')
.Key
.IsRequired.WithMessage('Informe a key ${key}')
.&End

.Value
.Trim
.&Not.IsEmpty.WithMessage('O ${key} deve ser informado!')
.IsNumeric.WithMessage('O ${key} não é um valor inválido!')
.&End
.&End
;

LResult := LJSONResult.Check;
Expand All @@ -462,8 +467,8 @@ function TForm2.ValidationTab2: IDataValidatorJSONResult;
if not Result then
AMessage := LResult.Informations.GetItem(0).Messages;
end)
.&End
.&End
.&End
end;

procedure TForm2.FormCreate(Sender: TObject);
Expand Down
Loading

0 comments on commit 50d90b6

Please sign in to comment.