Skip to content

Commit 50d90b6

Browse files
committed
Ajustes IsOptional
1 parent 05cfd1d commit 50d90b6

17 files changed

+229
-437
lines changed

DataValidator.delphilsp.json

+1-1
Large diffs are not rendered by default.

DataValidator.dpk

+7-6
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,24 @@ package DataValidator;
99
{$EXTENDEDSYNTAX ON}
1010
{$IMPORTEDDATA ON}
1111
{$IOCHECKS ON}
12-
{$LOCALSYMBOLS ON}
12+
{$LOCALSYMBOLS OFF}
1313
{$LONGSTRINGS ON}
1414
{$OPENSTRINGS ON}
15-
{$OPTIMIZATION OFF}
15+
{$OPTIMIZATION ON}
1616
{$OVERFLOWCHECKS OFF}
1717
{$RANGECHECKS OFF}
18-
{$REFERENCEINFO ON}
18+
{$REFERENCEINFO OFF}
1919
{$SAFEDIVIDE OFF}
20-
{$STACKFRAMES ON}
20+
{$STACKFRAMES OFF}
2121
{$TYPEDADDRESS OFF}
2222
{$VARSTRINGCHECKS ON}
2323
{$WRITEABLECONST OFF}
2424
{$MINENUMSIZE 1}
2525
{$IMAGEBASE $400000}
26-
{$DEFINE DEBUG}
26+
{$DEFINE RELEASE}
2727
{$ENDIF IMPLICITBUILDING}
28-
{$IMPLICITBUILD ON}
28+
{$RUNONLY}
29+
{$IMPLICITBUILD OFF}
2930

3031
requires
3132
rtl;

DataValidator.dproj

+75-318
Large diffs are not rendered by default.

samples/JSON/Basic/Basic.delphilsp.json

+1-1
Large diffs are not rendered by default.

samples/JSON/Basic/Basic.dproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
22
<PropertyGroup>
33
<ProjectGuid>{003881DF-B1A2-46DF-906B-76CFCE2C63D1}</ProjectGuid>
4-
<ProjectVersion>19.4</ProjectVersion>
4+
<ProjectVersion>19.5</ProjectVersion>
55
<FrameworkType>VCL</FrameworkType>
66
<Base>True</Base>
77
<Config Condition="'$(Config)'==''">Debug</Config>

samples/JSON/Basic/UBasic.dfm

-9
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ object Form2: TForm2
2323
Color = 2565927
2424
ParentBackground = False
2525
TabOrder = 0
26-
ExplicitHeight = 757
2726
object btnLimpar: TButton
2827
AlignWithMargins = True
2928
Left = 3
@@ -80,8 +79,6 @@ object Form2: TForm2
8079
Align = alClient
8180
BevelOuter = bvNone
8281
TabOrder = 1
83-
ExplicitWidth = 1244
84-
ExplicitHeight = 757
8582
object PageControl1: TPageControl
8683
Left = 0
8784
Top = 0
@@ -117,9 +114,6 @@ object Form2: TForm2
117114
Color = clCream
118115
ScrollBars = ssBoth
119116
TabOrder = 1
120-
ExplicitLeft = 600
121-
ExplicitWidth = 143
122-
ExplicitHeight = 603
123117
end
124118
end
125119
object TabSample2: TTabSheet
@@ -180,9 +174,6 @@ object Form2: TForm2
180174
Color = clCream
181175
ScrollBars = ssBoth
182176
TabOrder = 1
183-
ExplicitLeft = 600
184-
ExplicitWidth = 636
185-
ExplicitHeight = 727
186177
end
187178
end
188179
end

samples/JSON/Basic/UBasic.pas

+72-67
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,11 @@ function TForm2.ValidationTab2: IDataValidatorJSONResult;
245245

246246
.Value
247247
.Trim
248-
.&Not.IsEmpty.WithMessage('O ${key} deve ser informado!')
248+
.IsOptional(
249+
function(const AValue: TJSONValue): Boolean
250+
begin
251+
Result := AValue.Null;
252+
end)
249253
.IsJSONString.WithMessage('${key} - ${value} - Não é do tipo string!')
250254
.IsLength(10,10).WithMessage('${key} - Deve ter somente 10 caracteres!')
251255
.IsDate(False).WithMessage('${key} - ${value} - Não é uma data válida!')
@@ -375,84 +379,85 @@ function TForm2.ValidationTab2: IDataValidatorJSONResult;
375379
.IsEmail.WithMessage('${key} - ${value} - Não é um e-mail válido!')
376380
.&End
377381
.&End
382+
;
378383

379-
.Validate('items')
380-
.Key
381-
.IsRequired.WithMessage('Informe a key ${key}')
382-
.&End
384+
LResult := LJSONResult.Check;
383385

384-
.Value
385-
.IsJSONObject.WithMessage('${key} - Não é do tipo JSONObject!')
386-
.CustomJSONSubValidator(
387-
function(const AValue: IDataValidatorJSON; var AMessage: TDataValidatorMessage): Boolean
388-
var
389-
LJSONResult: IDataValidatorJSONResult;
390-
LResult: IDataValidatorResult;
391-
begin
392-
LJSONResult :=
393-
AValue
394-
.Validate('product_id')
395-
.Key
396-
.IsRequired.WithMessage('Informe a key ${key}')
397-
.&End
386+
Result := LResult.OK;
398387

399-
.Value
400-
.Trim
401-
.&Not.IsEmpty.WithMessage('O ${key} deve ser informado!')
402-
.IsJSONNumeric.WithMessage('${key} - ${value} - Não é do tipo numeric!')
403-
.IsGreaterThan(0).WithMessage('O ${key} deve ser maior que zero!')
404-
.IsInteger.WithMessage('O ${key} deve ser do tipo inteiro!')
405-
.&End
406-
.&End
388+
if not Result then
389+
AMessage := LResult.Informations.GetItem(0).Messages;
390+
end)
407391

408-
.Validate('product_name')
409-
.Key
410-
.IsRequired.WithMessage('Informe a key ${key}')
411-
.&End
392+
.&End
393+
.&End
412394

413-
.Value
414-
.Trim
415-
.&Not.IsEmpty.WithMessage('O ${key} deve ser informado!')
416-
.IsJSONString.WithMessage('${key} - ${value} - Não é do tipo string!')
417-
.IsAlphaNumeric(TDataValidatorLocaleLanguage.tl_pt_BR, ['-', ',', '/', '\']).WithMessage('${key} - ${value} - Não é um valor AlphaNumeric!')
418-
.&End
419-
.&End
395+
.Validate('items')
396+
.Key
397+
.IsRequired.WithMessage('Informe a key ${key}')
398+
.&End
420399

421-
.Validate('price')
422-
.Key
423-
.IsRequired.WithMessage('Informe a key ${key}')
424-
.&End
400+
.Value
401+
.IsJSONArray.WithMessage('${key} - Não é do tipo JSONArray!')
402+
.CustomJSONSubValidator(
403+
function(const AValue: IDataValidatorJSON; var AMessage: TDataValidatorMessage): Boolean
404+
var
405+
LJSONResult: IDataValidatorJSONResult;
406+
LResult: IDataValidatorResult;
407+
begin
408+
LJSONResult :=
409+
AValue
410+
.Validate('product_id')
411+
.Key
412+
.IsRequired.WithMessage('Informe a key ${key}')
413+
.&End
425414

426-
.Value
427-
.Trim
428-
.&Not.IsEmpty.WithMessage('O ${key} deve ser informado!')
429-
.IsNumeric.WithMessage('O ${key} não é um valor inválido!')
430-
.IsGreaterThan(-1).WithMessage('Informe um valor maior que Zero!')
431-
.&End
432-
.&End
415+
.Value
416+
.Trim
417+
.&Not.IsEmpty.WithMessage('O ${key} deve ser informado!')
418+
.IsJSONNumeric.WithMessage('${key} - ${value} - Não é do tipo numeric!')
419+
.IsGreaterThan(0).WithMessage('O ${key} deve ser maior que zero!')
420+
.IsInteger.WithMessage('O ${key} deve ser do tipo inteiro!')
421+
.&End
422+
.&End
433423

434-
.Validate('quantity')
435-
.Key
436-
.IsRequired.WithMessage('Informe a key ${key}')
437-
.&End
424+
.Validate('product_name')
425+
.Key
426+
.IsRequired.WithMessage('Informe a key ${key}')
427+
.&End
438428

439-
.Value
440-
.Trim
441-
.&Not.IsEmpty.WithMessage('O ${key} deve ser informado!')
442-
.IsNumeric.WithMessage('O ${key} não é um valor inválido!')
443-
.&End
444-
.&End
445-
;
429+
.Value
430+
.Trim
431+
.&Not.IsEmpty.WithMessage('O ${key} deve ser informado!')
432+
.IsJSONString.WithMessage('${key} - ${value} - Não é do tipo string!')
433+
.IsAlphaNumeric(TDataValidatorLocaleLanguage.tl_pt_BR, ['-', ',', '/', '\']).WithMessage('${key} - ${value} - Não é um valor AlphaNumeric!')
434+
.&End
435+
.&End
446436

447-
LResult := LJSONResult.Check;
437+
.Validate('price')
438+
.Key
439+
.IsRequired.WithMessage('Informe a key ${key}')
440+
.&End
448441

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

451-
if not Result then
452-
AMessage := LResult.Informations.GetItem(0).Messages;
453-
end)
454-
.&End
450+
.Validate('quantity')
451+
.Key
452+
.IsRequired.WithMessage('Informe a key ${key}')
455453
.&End
454+
455+
.Value
456+
.Trim
457+
.&Not.IsEmpty.WithMessage('O ${key} deve ser informado!')
458+
.IsNumeric.WithMessage('O ${key} não é um valor inválido!')
459+
.&End
460+
.&End
456461
;
457462

458463
LResult := LJSONResult.Check;
@@ -462,8 +467,8 @@ function TForm2.ValidationTab2: IDataValidatorJSONResult;
462467
if not Result then
463468
AMessage := LResult.Informations.GetItem(0).Messages;
464469
end)
470+
.&End
465471
.&End
466-
.&End
467472
end;
468473

469474
procedure TForm2.FormCreate(Sender: TObject);

0 commit comments

Comments
 (0)