From 30391cafb671633b10eac212beadd7f8b30f7fef Mon Sep 17 00:00:00 2001 From: Andrew Scott Date: Tue, 3 Dec 2024 14:00:28 -0800 Subject: [PATCH] cleanup --- src/IntelliTect.Coalesce/Api/Controllers/ApiActionFilter.cs | 5 +++-- .../Api/Controllers/CoalesceJsonReferenceHandler.cs | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) 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();