refactor(api): derive field name from property being validated

This commit is contained in:
Stevan Freeborn
2026-02-13 04:37:47 -06:00
parent 6fc8bd0366
commit e88adfd2a7
+4 -2
View File
@@ -9,12 +9,14 @@ public record Request : IValidatableObject
{ {
if (string.IsNullOrWhiteSpace(Username)) if (string.IsNullOrWhiteSpace(Username))
{ {
yield return new("The Username field is required.", [nameof(Username)]); var fieldName = nameof(Username);
yield return new($"The {fieldName} field is required.", [fieldName]);
} }
if (string.IsNullOrWhiteSpace(Password)) if (string.IsNullOrWhiteSpace(Password))
{ {
yield return new("The Password field is required.", [nameof(Password)]); var fieldName = nameof(Password);
yield return new($"The {fieldName} field is required.", [fieldName]);
} }
} }
} }