Skip to content

Avoid primary data to occur in included[] #1195

Closed
@bkoelman

Description

@bkoelman

DESCRIPTION

The primary resource is duplicated in the included array in rare corner cases, such as self-referencing relationships or cyclic relationship chains.

I don't know if this was a deliberate choice or just an unnoticed side effect during initial implementation (many years ago, before I joined the project). The behavior could be considered convenient, because clients parsing the included array can look up everything in the array, without falling back to the primary data.

We've changed the logic to build the include array multiple times. But before doing so, we added tests to capture the existing behavior. Therefore it's still working this way today.

The JSON:API specification used to be agnostic about this, but with its recent rewording, this is no longer allowed:

Every included resource object MUST be identified via a chain of relationships originating in a document’s primary data. This means that compound documents require “full linkage” and that no resource object can be included without a direct or indirect relationship to the document’s primary data.

The only exception to the full linkage requirement is when relationship fields that would otherwise contain linkage data are excluded due to sparse fieldsets requested by the client.

STEPS TO REPRODUCE

See cases in IntegrationTests/QueryStrings/Includes/IncludeTests.cs.

EXPECTED BEHAVIOR

The primary resource is never duplicated in the included array in response bodies.

ACTUAL BEHAVIOR

Duplication may occur.

VERSIONS USED

  • JsonApiDotNetCore version: 5.0.3
  • ASP.NET Core version: 6.0
  • Entity Framework Core version: N/A
  • Database provider: N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions