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

RuleForEach with NotEmpty/NotNull on array properties marks array property as Required #118

Open
baguwka opened this issue Oct 27, 2022 · 0 comments

Comments

@baguwka
Copy link

baguwka commented Oct 27, 2022

Hello
I've noticed a possible issue with RuleForEach for array fields of query parameters.
Here is an example with the behavior I reproduced:
https://github.com/baguwka/swashbuckle.validation.issue.ruleforeach/blob/master/RuleForEachValidation/Controller.cs

Dto

public class QueryDto
{
    public long[]? Field{ get; set; }
}

Controller

public IActionResult Test([FromQuery]QueryDto parameters)
{
   return Ok();
}

Validator

RuleForEach(x => x.Field).NotEmpty();

Actual swagger scheme

"parameters": [
  {
    "name": "Field",
    "in": "query",
    "required": true,
    "schema": {
      "type": "array",
      "items": {
        "type": "integer",
        "format": "int64"
      },
      "nullable": true
    }
  }
],

Parameter Field must not be required, since RuleForEach with NotEmpty/NotNull of FluentValidator not restricting accepting null Field array.

@baguwka baguwka changed the title RuleForEach on array properties marks array property as Required RuleForEach with NotEmpty/NotNull on array properties marks array property as Required Oct 27, 2022
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