Skip to content

Commit

Permalink
Merge pull request #97 from neuroglia-io/fix-problem-details
Browse files Browse the repository at this point in the history
Fixed the problem details to make it cross-compatible with the ASP.NET implementation
  • Loading branch information
cdavernas authored Jun 26, 2024
2 parents 2f7c4fe + 1d647d6 commit ac7c6bf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/Neuroglia.Core/ProblemDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public ProblemDetails() { }
/// <param name="instance">A <see cref="Uri"/> reference that identifies the specific occurrence of the problem.It may or may not yield further information if dereferenced</param>
/// <param name="errors">An optional collection containing error messages mapped per error code</param>
/// <param name="extensionData">A mapping containing problem details extension data, if any</param>
public ProblemDetails(Uri type, string title, int status, string? detail = null, Uri? instance = null, IEnumerable<KeyValuePair<string, string[]>>? errors = null, IDictionary<string, object>? extensionData = null)
public ProblemDetails(Uri type, string title, int status, string? detail = null, Uri? instance = null, IDictionary<string, string[]>? errors = null, IDictionary<string, object>? extensionData = null)
{
this.Type = type ?? throw new ArgumentNullException(nameof(type));
this.Title = title ?? throw new ArgumentNullException(nameof(title));
this.Status = status;
this.Detail = detail;
this.Instance = instance;
this.Errors = errors?.WithValueSemantics();
this.Errors = errors;
this.ExtensionData = extensionData;
}

Expand Down Expand Up @@ -84,7 +84,7 @@ public ProblemDetails(Uri type, string title, int status, string? detail = null,
/// Gets/sets an optional collection containing error messages mapped per error code
/// </summary>
[DataMember(Order = 6, Name = "errors"), JsonPropertyName("errors")]
public virtual EquatableList<KeyValuePair<string, string[]>>? Errors { get; set; }
public virtual IDictionary<string, string[]>? Errors { get; set; }

/// <summary>
/// Gets/sets a mapping containing problem details extension data, if any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// limitations under the License.

using Neuroglia.Data.Infrastructure.ResourceOriented.Properties;
using System.Linq;
using System.Net;

namespace Neuroglia.Data.Infrastructure.ResourceOriented;
Expand All @@ -37,7 +38,7 @@ public static ProblemDetails ResourceSchemaValidationFailed(IResourceReference r
(int)HttpStatusCode.BadRequest,
StringFormatter.Format(ProblemDescriptions.ResourceSchemaValidationFailed, resource.Definition.Group, resource.Definition.Version, resource.Definition.Plural),
null,
evaluationResults.Errors?.Select(e => new KeyValuePair<string, string[]>(e.Key, [e.Value]))
evaluationResults.Errors?.ToDictionary(e => e.Key, e => new string[] { e.Value })
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected virtual async Task<AdmissionReviewResponse> ValidateAsync(AdmissionRev

var results = tasks.Select(t => t.Result);
if (results.All(t => t.Allowed)) return new(request.Uid, true);
else return new(request.Uid, false, null, new ProblemDetails(ProblemTypes.AdmissionFailed, ProblemTitles.AdmissionFailed, (int)HttpStatusCode.BadRequest, errors: results.Where(r => !r.Allowed && r.Problem != null && r.Problem.Errors != null).SelectMany(r => r.Problem!.Errors!)));
else return new(request.Uid, false, null, new ProblemDetails(ProblemTypes.AdmissionFailed, ProblemTitles.AdmissionFailed, (int)HttpStatusCode.BadRequest, errors: results.Where(r => !r.Allowed && r.Problem != null && r.Problem.Errors != null).SelectMany(r => r.Problem!.Errors!).ToDictionary(e => e.Key, e => e.Value)));
}

}

0 comments on commit ac7c6bf

Please sign in to comment.