Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ascott18 committed Dec 3, 2024
1 parent a46b373 commit 30391ca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/IntelliTect.Coalesce/Api/Controllers/ApiActionFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class ApiActionFilter : IApiActionFilter
protected readonly ILogger<ApiActionFilter> logger;
protected readonly IOptions<CoalesceOptions> options;

private static readonly MediaTypeHeaderValue RefTypeHeader = new MediaTypeHeaderValue("application/json+ref");

public ApiActionFilter(ILogger<ApiActionFilter> logger, IOptions<CoalesceOptions> options)
{
this.logger = logger;
Expand Down Expand Up @@ -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<IOptions<JsonOptions>>()?.Value ?? new JsonOptions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

namespace IntelliTect.Coalesce.Api.Controllers;


/// <summary>
/// A modified implementation of the default <see cref="PreserveReferenceResolver"/> that
/// avoids putting IDs/refs on items that will never be duplicated (the root response, and collections).
/// </summary>
internal sealed class CoalesceJsonReferenceHandler : ReferenceHandler
{
public override ReferenceResolver CreateResolver() => new PreserveReferenceResolver();
Expand Down

0 comments on commit 30391ca

Please sign in to comment.