CarterCommunity / Carter

Carter is framework that is a thin layer of extension methods and functionality over ASP.NET Core allowing code to be more explicit and most importantly more enjoyable.
MIT License
2.11k stars 174 forks source link

Added a new extension for ValidationResult #281

Closed isaacOjeda closed 2 years ago

isaacOjeda commented 2 years ago

New extension for ValidationResult called GetValidationProblems.

Example Usage:

var result = request.Validate(command);

if (!result.IsValid)
{
     return Results.ValidationProblem(result.GetValidationProblems());
}

Response:

{
  "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
  "title": "One or more validation errors occurred.",
  "status": 400,
  "errors": {
    "Name": [
      "'Name' no debería estar vacío."
    ],
    "Description": [
      "'Description' no debería estar vacío."
    ],
    "Price": [
      "'Price' no debería estar vacío."
    ]
  }
}
jchannon commented 2 years ago

This looks great, thanks!

I'll try and get it merged in with the next Carter release once .NET6 is out

On Sun, 7 Nov 2021 at 01:51, Isaac Ojeda @.***> wrote:

New extension for ValidationResult called GetValidationProblems.

Example Usage:

var result = request.Validate(command);

if (!result.IsValid)

{

 return Results.ValidationProblem(result.ToValidationProblems());

}

Response:

{

"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",

"title": "One or more validation errors occurred.",

"status": 400,

"errors": {

"Name": [

  "'Name' no debería estar vacío."

],

"Description": [

  "'Description' no debería estar vacío."

],

"Price": [

  "'Price' no debería estar vacío."

]

}

}


You can view, comment on, or merge this pull request online at:

https://github.com/CarterCommunity/Carter/pull/281 Commit Summary

File Changes

(1 file https://github.com/CarterCommunity/Carter/pull/281/files)

Patch Links:

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/CarterCommunity/Carter/pull/281, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAZVJUWV37IW4WG6WODTITUKXLQJANCNFSM5HQHWVLQ .

jchannon commented 2 years ago

Thanks @isaacOjeda 👍