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

MaxItems array validation not reflecting in swagger schema for query parameters #132

Open
jleon15 opened this issue May 26, 2023 · 0 comments

Comments

@jleon15
Copy link

jleon15 commented May 26, 2023

Hey everyone! We are using Fluent Validation for all of our API request models but those that contain maximum items validation on arrays in query parameters do not get the maxItems property set in the swagger schema.

Those arrays that are in the body and have the same validation applied do get reflected in the schema.

For example, for this request model:

public class GetTenantMembersModel : PaginatedQueryModel
{
    [FromQuery(Name = "user_id")]
    [JsonProperty("user_id")]
    public List<Guid> UserIds { get; set; } = new();

    ... 
}

We have the following validator

public class GetTenantMembersModelValidator : AbstractValidator<GetTenantMembersModel>
{
    public GetTenantMembersModelValidator()
    {
        RuleFor(x => x.UserIds)
            .MaximumItems(50)
            .WithMessage(ErrorMessages.HasMaximumItemsOfMaxItems)
            .ForPropertyName("user_id");

        ...
    }
}

And it results in the following swagger schema:

Screenshot 2023-05-26 at 12 39 10

As you can see, the maxItems property is not set, but for body parameters it is set using the exact same validation.

If I go ahead and use the [MaxLength(50)] ComponentModel annotation, it is added to the schema:

image

Is this a known issue? Is there any workaround? Thanks in advance!

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