diff --git a/src/IntelliTect.Coalesce/Api/Controllers/ApiActionFilter.cs b/src/IntelliTect.Coalesce/Api/Controllers/ApiActionFilter.cs index 68cc5f24..d9dc07f5 100644 --- a/src/IntelliTect.Coalesce/Api/Controllers/ApiActionFilter.cs +++ b/src/IntelliTect.Coalesce/Api/Controllers/ApiActionFilter.cs @@ -27,6 +27,8 @@ public class ApiActionFilter : IApiActionFilter protected readonly ILogger logger; protected readonly IOptions options; + private static readonly MediaTypeHeaderValue RefTypeHeader = new MediaTypeHeaderValue("application/json+ref"); + public ApiActionFilter(ILogger logger, IOptions options) { this.logger = logger; @@ -119,8 +121,7 @@ public virtual void OnActionExecuted(ActionExecutedContext context) if (context.Result is ObjectResult result) { - var refHeader = new MediaTypeHeaderValue("application/json+ref"); - if (context.HttpContext.Request.GetTypedHeaders().Accept.Any(h => h.IsSubsetOf(refHeader))) + if (context.HttpContext.Request.GetTypedHeaders().Accept.Any(h => h.IsSubsetOf(RefTypeHeader))) { var jsonOptions = context.HttpContext.RequestServices.GetService>()?.Value ?? new JsonOptions { diff --git a/src/IntelliTect.Coalesce/Api/Controllers/CoalesceJsonReferenceHandler.cs b/src/IntelliTect.Coalesce/Api/Controllers/CoalesceJsonReferenceHandler.cs index ef16d8ea..7ec245fc 100644 --- a/src/IntelliTect.Coalesce/Api/Controllers/CoalesceJsonReferenceHandler.cs +++ b/src/IntelliTect.Coalesce/Api/Controllers/CoalesceJsonReferenceHandler.cs @@ -7,7 +7,10 @@ namespace IntelliTect.Coalesce.Api.Controllers; - +/// +/// A modified implementation of the default that +/// avoids putting IDs/refs on items that will never be duplicated (the root response, and collections). +/// internal sealed class CoalesceJsonReferenceHandler : ReferenceHandler { public override ReferenceResolver CreateResolver() => new PreserveReferenceResolver();