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:

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:
When I generate the Swagger docs for this, I get a Stack Overflow Exception: