micro-elements/MicroElements.Swashbuckle.FluentValidation

RuleForEach rules are not in OAS anymore after updating to 5.1.0

crnd opened this issue · 1 comments

crnd commented

After updating MicroElements.Swashbuckle.FluentValidation to version 5.1.0 the RuleForEach rules from FluentValidation are no longer present on the OpenAPI Specification.

There's a repository at https://github.com/crnd/ruleforeach-issue that contains code to reproduce the issue. The newest commit contains the newest version with RuleForEach definitions missing from the OAS and the first commit contains the last working versions with RuleForEach definitions present in the OAS.

The issue can be replicated by using the following objects for example during a POST call:

// Command object to send in a POST call.
public class CreateBookshelfCommand
{
    public string[] Books { get; set; }
}

// Validator to validate that command.
public class CreateBookshelfCommandValidator : AbstractValidator<CreateBookshelfCommand>
{
    CreateBookshelfCommandValidator()
    {
        RuleFor(c => c.Books)
            .NotEmpty();

        RuleForEach(c => c.Books)
            .NotEmpty()
            .MinimumLength(5)
            .MaximumLength(250);
    }
}

With FluentValidation version 9.5.4and MicroElements.Swashbuckle.FluentValidation version 4.3.0 the generated OAS contains the following definition for CreateBookshelfCommand:

"CreateBookshelfCommand": {
  "required": [
    "books"
  ],
  "type": "object",
  "properties": {
    "books": {
      "minlength": 1,
      "type": "array",
      "items": {
        "maxLength": 250,
        "minLength": 5,
        "type": "string"
      }
    }
  },
  "additionalProperties": false
}

With FluentValidation version 10.3.0and MicroElements.Swashbuckle.FluentValidation version 5.1.0 the generated OAS contains the following definition for CreateBookshelfCommand:

"CreateBookshelfCommand": {
  "required": [
    "books"
  ],
  "type": "object",
  "properties": {
    "books": {
      "minlength": 1,
      "type": "array",
      "items": {
        "type": "string"
      }
    }
  },
  "additionalProperties": false
}

The only difference is that the length definitions defined in the RuleForEach are not present in the OAS generated with the latest versions.

Look at 5.2.0
Also "minlength": 1 will be changed to "minItems": 1 (minlength can be applied only to strings)