Skip to content

Conversation

PawelSuwinski
Copy link
Contributor

Generate setter method instead of adder and remover for simple arrays option for backward compatibility turned off by default.

Having adder and remover denormalization of simple arrays needs usage of reflection based PropertyNormalizer to keep sent keys (to reset keys in fact), because array can't be just replaced with new one using entity interface and this is needed for proper item indexing in validation message and json serialization for example on Mercure pushes usage (arrays are serialized as json object not as arrays), ex:

curl -X 'GET' \
  'https://localhost/projects/642969' \
  -H 'accept: application/ld+json'
{
  "@context": "/contexts/Project",
  "@id": "/projects/642969",
  // ...
  "shareWith": [
    "test@example.com"
  ]
}

curl -X 'PATCH' \
  'https://localhost/projects/642969' \
  -H 'accept: application/ld+json' \
  -H 'Content-Type: application/merge-patch+json' \
  -d '{
  "shareWith": [
    "test3@"
  ]
}'
{
  "@context": "/contexts/ConstraintViolationList",
  "@id": "/validation_errors/bd79c0ab-ddba-46cc-a703-a7a4b08de310",
  "@type": "ConstraintViolationList",
  "status": 422,
  "violations":
    {
      "propertyPath": "shareWith[1]", // <-- should be 0 as it is serialized in GET
      "message": "This value is not a valid email address.",
      "code": "bd79c0ab-ddba-46cc-a703-a7a4b08de310"
    }
  ],

If valid value is sent (ex. 'test3@example.com') and it is used in mercure push it is serialized as json object {"1": "test1@example.com"} in request body however on the frontend site by OpenApi/ Hydra docs we expects an array so without custom handling it crash on array operations (ex. project.shareWith.map(//...)).

@PawelSuwinski
Copy link
Contributor Author

PawelSuwinski commented Sep 11, 2025

Resolve #435

@PawelSuwinski PawelSuwinski force-pushed the simple-array-setter branch 3 times, most recently from 649661b to 6fa2172 Compare September 11, 2025 12:56
@PawelSuwinski
Copy link
Contributor Author

PawelSuwinski commented Sep 19, 2025

RFR, WDYT @dunglas? (If is there any other active maintainer of this repo to ask for review please let me know.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant