Declarative Validation for nested collections?

Thanks for the example. I’ve just added support for declarative collection validation in this commit where if your IEnumerable<T> collection has validators it will auto register the declarative collection validator for that type so it should now work as expected.

When a single child collection validator is thrown your Error ResponseStatus DTO should look something like:

{
    ErrorCode: "MaximumLength",
    Message: "The length of 'Value' must be 20 characters or fewer. You entered 32 characters.",
    Errors: [{
        FieldName: "Parameters[0].Value"
        ErrorCode: "MaximumLength",
        Message: "The length of 'Value' must be 20 characters or fewer. You entered 32 characters.",
    }]
}

Registering declarative collection validators is enabled by default and can be disabled with:

Plugins.Add(new ValidationFeature { 
    ImplicitlyValidateChildProperties = false
});

This change is available from the latest v5.10.5 that’s now available on MyGet.

2 Likes