Skip to content

StackOverflowException when generating swagger for an object with Fluent Validators in a tree structure #125

Description

@johnkwaters

I have a DTO that has an Items property that recursively contains other Items - it's a tree of Items
I use the same fluent validator for all the items:

    public class UpdateEstimateItemDTO : IEntity
    {
        public long LineNumber { get; set; }
        public string Title { get; set; }
        public decimal Min { get; set; }
        public decimal Max { get; set; }
        public List<UpdateEstimateItemDTO>? Items { get; set; }

        public class UpdateEstimateItemValidator : AbstractValidator<UpdateEstimateItemDTO>
        {
            public UpdateEstimateItemValidator()
            {
                RuleFor(x => x.Title).NotEmpty().MaximumLength(256);
                RuleFor(x => x.LineNumber).GreaterThanOrEqualTo(0);
                RuleFor(x => x.Min).GreaterThanOrEqualTo(0.0m);
                RuleFor(x => x.Max).GreaterThanOrEqualTo(0.0m);
                RuleFor(x => x.Min)
                    .Must((item, min) => min <= item.Max)
                    .WithMessage("Min must be less than or equal to max");
                RuleForEach(x => x.Items).SetValidator(this);
            }
        }
    }

When I generate the Swagger docs for this, I get a Stack Overflow Exception:

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions