Skip to content

Commit

Permalink
Ajustes gerais
Browse files Browse the repository at this point in the history
  • Loading branch information
dliocode committed Sep 27, 2021
1 parent efcbcf4 commit 60e1a52
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/core/DataValidator.JSON.Context.pas
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,25 @@ function TDataValidatorJSONContext<T>.Value: IDataValidatorJSONContextValue<T>;
function TDataValidatorJSONContext<T>.IsOptional: IDataValidatorJSONContextKey<T>;
begin
Result := Self;
Add(TDataValidatorJSONKeyIsOptional.Create(nil, 'Key is optional!'));
Add(TDataValidatorJSONKeyIsOptional.Create(nil, 'Key ${key} is optional!'));
end;

function TDataValidatorJSONContext<T>.IsOptional(const AExecute: TDataValidatorFuncExecute): IDataValidatorJSONContextKey<T>;
begin
Result := Self;
Add(TDataValidatorJSONKeyIsOptional.Create(AExecute, 'Key is optional!'));
Add(TDataValidatorJSONKeyIsOptional.Create(AExecute, 'Key ${key} is optional!'));
end;

function TDataValidatorJSONContext<T>.IsRequired: IDataValidatorJSONContextKey<T>;
begin
Result := Self;
Add(TDataValidatorJSONKeyIsRequired.Create(nil, 'Key is required!'));
Add(TDataValidatorJSONKeyIsRequired.Create(nil, 'Key ${key} is required!'));
end;

function TDataValidatorJSONContext<T>.IsRequired(const AExecute: TDataValidatorFuncExecute): IDataValidatorJSONContextKey<T>;
begin
Result := Self;
Add(TDataValidatorJSONKeyIsRequired.Create(AExecute, 'Key is required!'));
Add(TDataValidatorJSONKeyIsRequired.Create(AExecute, 'Key ${key} is required!'));
end;

function TDataValidatorJSONContext<T>.WithMessage(const AMessage: string): IDataValidatorJSONContextKey<T>;
Expand Down
5 changes: 4 additions & 1 deletion src/core/DataValidator.JSON.pas
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ implementation
uses
DataValidator.Information.Intf, DataValidator.ItemBase.Intf, DataValidator.Context.Intf,
DataValidator.JSON.Base, DataValidator.Information, DataValidator.ItemBase.Sanitizer, DataValidator.ItemBase,
Validator.JSON.Key.IsOptional, Validator.IsOptional;
Validator.JSON.Key.IsRequired, Validator.JSON.Key.IsOptional, Validator.IsOptional;

{ TDataValidatorJSON }

Expand Down Expand Up @@ -202,6 +202,9 @@ function TDataValidatorJSON.CheckValueObject(const ACheckAll: Boolean): IDataVal
LOK := False;
LInfo.Add(LValidatorResult.Informations as IDataValidatorInformations);

if (LValidatorItem is TDataValidatorJSONKeyIsRequired) then
Break;

if not ACheckAll then
Break;
end
Expand Down
2 changes: 1 addition & 1 deletion src/validators/Validator.JSON.Key.IsRequired.pas
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function TDataValidatorJSONKeyIsRequired.Check: IDataValidatorResult;
LJSONPair: TJSONPair;
begin
LValue := GetValueAsString;
R := False;
R := True;
LIsRequired := True;

if Assigned(FFuncExecute) then
Expand Down

0 comments on commit 60e1a52

Please sign in to comment.