Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support DataAnnotations Validation #327

Open
gao-artur opened this issue Mar 18, 2024 · 0 comments
Open

Support DataAnnotations Validation #327

gao-artur opened this issue Mar 18, 2024 · 0 comments

Comments

@gao-artur
Copy link

There was a request in the past that was closed due to inactivity: #51.
It would be great to add support for the validation attributes defined in the System.ComponentModel.DataAnnotations namespace.

For example:

[ProtoContract]
public class Person
{
    [Required]
    [MinLength(2)]
    [ProtoMember(1)]
    public string FirstName { get; set; }

    [Required]
    [MinLength(2)]
    [ProtoMember(2)]
    public string LastName { get; set; }
}

Sending null value in the FirstName and a in LastName properties should produce an error similar to what Asp.Net Core does when sending a REST request:

{
  "errors": {
    "LastName": [
      "The field LastName must be a string or array type with a minimum length of '2'."
    ],
    "FirstName": [
      "The FirstName field is required."
    ]
  },
  "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
  "title": "One or more validation errors occurred.",
  "status": 400,
  "traceId": "00-8b40c8ee54cacbefc8bf5338c0c7c809-51bfdad1f249172a-01"
}

Ideally, it should be possible to enable the validation on the server and client sides (why send the request that for sure will fail the validation?)

Alternative solution:
Use 3rd party libraries to enable validations with interceptors, like grpc-aspnetcore-validator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant