Skip to content

feat: add option to stop validation after first validation error #188

@HonoluluHenk

Description

@HonoluluHenk

If i apply the following annotations:

  @IsNotEmpty()
  @IsInt()
  @Min(0)
  foobar: number;

The validation result will be:

{ 
  "value": null, 
  "property": "foobar", 
  "children": [], 
  "constraints": {
    "min": "foobar must be greater than 0",
   "isInt": "foobar must be an integer number", 
   "isNotEmpty": "foobar should not be empty" 
  } 
}

If no value is given (i.e.: foobar === null), I only want the validation result of @IsNotEmpty.
All the others are quite useless... worse: since the validation errors (the constraints) are stored in an object, the ordering is lost so I cannot "just take the first error constraint" :(

Expected result:

{ 
  "value": null, 
  "property": "foobar", 
  "children": [], 
  "constraints": {
   "isNotEmpty": "foobar should not be empty" 
  } 
}

or:

 { 
  "value": null, 
  "property": "foobar", 
  "children": [], 
  "constraints": [
    {"isNotEmpty": "foobar should not be empty" },
    {"isInt": "foobar must be an integer number"},
    { "min": "foobar must be greater than 0"}
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: done/releasedIssue has been completed, no further action is needed.type: featureIssues related to new features.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions