Skip to content

Improved ModelState validation #834

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

Closed
bart-degreed opened this issue Sep 21, 2020 · 0 comments · Fixed by #847
Closed

Improved ModelState validation #834

bart-degreed opened this issue Sep 21, 2020 · 0 comments · Fixed by #847
Assignees

Comments

@bart-degreed
Copy link
Contributor

We currently have a solution in place to enable partial patch, combined with required fields. Users need to add [IsRequired] instead of the built-in [Required] attribute on their resource properties.

Although it works, downsides of this approach are:

  • Because IsRequired derives from Required, it is picked up by EF Core to generate non-null database columns. But other tools may not recognize it.
  • At the time that validation logic inside [IsRequired] runs, we have no way to know where in the object graph we are. This is important because on relationship updates, only their IDs are sent, so we must turn off some checks. The way this is implemented now is kinda hacky, but seems to work (even with self-referencing entities in basic scenarios).
  • The current solution cannot work when we need to validate multiple resources per request (atomic operations).

A quick search made us suspect there's a better way, by interacting with the validation process instead of inventing our own attribute. See https://stackoverflow.com/questions/36982370/is-it-possible-to-use-a-custom-modelstate-validation-provider-in-asp-net-core for details.

This issue tracks the work to deprecate [IsRequired] and plug into the ModelState validation process instead.

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

Successfully merging a pull request may close this issue.

2 participants