From 43abcba81679ad95b9857981f1aaab3d95251778 Mon Sep 17 00:00:00 2001 From: Maksym Sadovnychyy Date: Mon, 3 Nov 2025 18:22:02 +0100 Subject: [PATCH] (bugfix): when returning ProblemDetail should be applicaiton/problem+json --- src/MaksIT.Results/MaksIT.Results.csproj | 2 +- src/MaksIT.Results/Mvc/ObjectResult.cs | 10 +++++++--- src/MaksIT.Results/Mvc/ProblemDetails.cs | 12 ++++-------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/MaksIT.Results/MaksIT.Results.csproj b/src/MaksIT.Results/MaksIT.Results.csproj index 2722e1a..555ac63 100644 --- a/src/MaksIT.Results/MaksIT.Results.csproj +++ b/src/MaksIT.Results/MaksIT.Results.csproj @@ -8,7 +8,7 @@ MaksIT.Results - 1.1.0 + 1.1.1 Maksym Sadovnychyy MAKS-IT MaksIT.Results diff --git a/src/MaksIT.Results/Mvc/ObjectResult.cs b/src/MaksIT.Results/Mvc/ObjectResult.cs index fc0c739..f320eaf 100644 --- a/src/MaksIT.Results/Mvc/ObjectResult.cs +++ b/src/MaksIT.Results/Mvc/ObjectResult.cs @@ -1,8 +1,6 @@ using System.Text.Json; -using System.Text.Json.Serialization; using Microsoft.AspNetCore.Mvc; - namespace MaksIT.Results.Mvc; public class ObjectResult(object? value) : IActionResult { @@ -20,7 +18,13 @@ public class ObjectResult(object? value) : IActionResult { response.StatusCode = StatusCode.Value; } - response.ContentType = "application/json"; + // Set content type based on value type + if (Value is ProblemDetails) { + response.ContentType = "application/problem+json"; + } + else { + response.ContentType = "application/json"; + } if (Value is not null) { await JsonSerializer.SerializeAsync( diff --git a/src/MaksIT.Results/Mvc/ProblemDetails.cs b/src/MaksIT.Results/Mvc/ProblemDetails.cs index b90a11f..b6bf09d 100644 --- a/src/MaksIT.Results/Mvc/ProblemDetails.cs +++ b/src/MaksIT.Results/Mvc/ProblemDetails.cs @@ -1,15 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +namespace MaksIT.Results.Mvc; -namespace MaksIT.Results.Mvc; public class ProblemDetails { - public int? Status { get; set; } + public string? Type { get; set; } public string? Title { get; set; } + public int? Status { get; set; } public string? Detail { get; set; } public string? Instance { get; set; } - public IDictionary Extensions { get; } = new Dictionary(); + public IDictionary Extensions { get; set; } = new Dictionary(); } \ No newline at end of file