Add arity key on field data returned by jsonapi

Created on 15 April 2022, about 2 years ago
Updated 22 March 2023, about 1 year ago

Problem/Motivation

#2864680: Spec Compliance: JSON API's schema disallows duplicate resource identifiers. EntityReferenceItems which reference the same entity must have an "arity" β†’ added an arity key to relationships returned by jsonapi to avoid an error when a reference field contains the same entity multiple times.

However, we have a similar problem when returning data about a specific field.
The previous fix only applies to ResourceIdentifier, but when querying a field, jsonapi returns normalized ResourceObject and those don't have an arity key.

Steps to reproduce

  1. Create an entity with a reference field and add the same entity multiple times in this reference field.
  2. Browse to /jsonapi/[entity_type]/[bundle]/[uuid]/[field_name] (real life example: /jsonapi/paragraph/carrousel/2f03a78f-1d0a-43e5-a6ee-6fb0fd8a90f7/field_images).
  3. You get this error:

    A JSON:API response failed validation (see the logs for details). Please report this in the issue queue on drupal.org

(However /jsonapi/[entity_type]/[bundle]/[uuid] does not have the same error because there, the relationship has arity keys.)

Proposed resolution

jsonapi should add an arity key on duplicated ResourceObject objects.

The arity logic from ResourceIdentifier should probably be refactorized to be used by other classes.

πŸ› Bug report
Status

Active

Version

9.5

Component
JSON APIΒ  β†’

Last updated 1 day ago

Created by

πŸ‡«πŸ‡·France prudloff Lille

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024