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

Disabling validation of parameters with [NeverValidate] #13

Closed
jonmotos opened this issue Oct 2, 2023 · 3 comments
Closed

Disabling validation of parameters with [NeverValidate] #13

jonmotos opened this issue Oct 2, 2023 · 3 comments
Labels
enhancement New feature or request
Milestone

Comments

@jonmotos
Copy link
Contributor

jonmotos commented Oct 2, 2023

It would be great if we could disable validation on specific parameters with the existing [NeverValidate] attribute.
Expected behavior from the existing model validation is to:

  1. Ignore any classes marked with this attribute
  2. Ignore any parameters marked with this attribute

I took a look in the action filter but it appears to be quite difficult to get the attributes of the parameter.

I'd be happy to take a look and implement if there is any interest in this.

@mvdgun
Copy link
Member

mvdgun commented Oct 3, 2023

Hi Jon, I think it's possible by casting each parameter variable in the foreach (var parameter in controllerActionDescriptor.Parameters) loop at line 51. Did some quick testing and this seems to work;

var parameterAttributes = ((ControllerParameterDescriptor) parameter).ParameterInfo.CustomAttributes;

The if check needs to be adjusted to check if there is a [ValidateNever] attribute present. Furthermore, a new condition needs to be created to check the presence of that attribute on the method and/or class, I think we can use endpoint.Metadata.OfType<FluentValidationAutoValidationAttribute>().Any() for that purpose.

The only thing I am currently debating is whether the check for the [ValidateNever] attribute always needs to fire or only when the DisableBuiltInModelValidation option is set to false.

@mvdgun mvdgun added this to the v1.3 milestone Oct 3, 2023
@mvdgun mvdgun added the enhancement New feature or request label Oct 3, 2023
@mvdgun
Copy link
Member

mvdgun commented Oct 9, 2023

Did some more digging but this one is becoming rather complex. I am going to push this issue to v1.4 for now.

@mvdgun
Copy link
Member

mvdgun commented Dec 17, 2023

@JonAdamsFromNC this one just got released in v1.4!

@mvdgun mvdgun closed this as completed Dec 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants