aspnetcore: Add overloads for validation problem results that accept IReadOnlyDictionary

Sometimes all you have is a IReadOnlyDictionary and you don’t want to have to downcast it or wrap it to pass it to the helper methods.

namespace Microsoft.AspNetCore.Http;

public static class Results
{
+    public static IResult ValidationProblem(IReadOnlyDictionary<string, string[]> errors,
+        string? detail = null,
+        string? instance = null,
+        int? statusCode = null,
+        string? title = null,
+        string? type = null,
+        IReadOnlyDictionary<string, object?>? extensions = null);

+    public static IResult Problem(
+        string? detail = null,
+        string? instance = null,
+        int? statusCode = null,
+        string? title = null,
+        string? type = null,
+        IReadOnlyDictionary<string, object?>? extensions = null);
}

public static class TypedResults
{
+    public static ValidationProblem ValidationProblem(IReadOnlyDictionary<string, string[]> errors,
+        string? detail = null,
+        string? instance = null,
+        string? title = null,
+        string? type = null,
+        IReadOnlyDictionary<string, object?>? extensions = null);

+    public static ProblemHttpResult Problem(
+        string? detail = null,
+        string? instance = null,
+        string? title = null,
+        string? type = null,
+        IReadOnlyDictionary<string, object?>? extensions = null);
}

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (14 by maintainers)

Most upvoted comments

API Review Notes:

  • Is this a breaking change? Yes. It’s ambiguous which overload to pick if you pass in Dictionary<string, string[]>.
  • Can we make it IEnumerable<KeyValuePair<string, string[]>> instead? Yes.
  • Do we want to change both the errors and extensions parameters? Might as well. It will accept more arguments, and we’re not modifying either dictionary.

API Approved!

namespace Microsoft.AspNetCore.Http;

public static class Results
{
+    public static IResult ValidationProblem(IEnumerable<KeyValuePair<string, string[]>> errors,
+        string? detail = null,
+        string? instance = null,
+        int? statusCode = null,
+        string? title = null,
+        string? type = null,
+        IEnumerable<KeyValuePair<string, object?>>? extensions = null);

+    public static IResult Problem(
+        string? detail = null,
+        string? instance = null,
+        int? statusCode = null,
+        string? title = null,
+        string? type = null,
+        IEnumerable<KeyValuePair<string, object?>>? extensions = null);
}

public static class TypedResults
{
+    public static ValidationProblem ValidationProblem(IEnumerable<KeyValuePair<string, string[]>> errors,
+        string? detail = null,
+        string? instance = null,
+        string? title = null,
+        string? type = null,
+        IEnumerable<KeyValuePair<string, object?>>? extensions = null);

+    public static ProblemHttpResult Problem(
+        string? detail = null,
+        string? instance = null,
+        int? statusCode = null,
+        string? title = null,
+        string? type = null,
+        IEnumerable<KeyValuePair<string, object?>>? extensions = null);
}

@halter73 thank you for reopening this one. I already opened #56370 about the new constructor for HttpValidationProblemDetails.