symfony: [Serializer] allow ObjectNormalizer to provide ConstraintViolationListInterface from ExtraAttributesException

Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? yes
Symfony version 3.3

Currently, I’m using API platform with the Symfony serializer and ALLOW_EXTRA_ATTRIBUTES=false

If my request produces a constraint violation, the error looks like:

{
    "type": "https://tools.ietf.org/html/rfc2616#section-10",
    "title": "An error occurred",
    "detail": "extendedAttributes.foo: This value should not be blank.",
    "violations": [
        {
            "propertyPath": "extendedAttributes.foo",
            "message": "This value should not be blank."
        }
    ]
}

But, if I provide an invalid attribute, the message looks like:

{
    "type": "https://tools.ietf.org/html/rfc2616#section-10",
    "title": "An error occurred",
    "detail": "Extra attributes are not allowed (\"foo2\" are unknown)."
}

Two things to note:

  1. there is no violations
  2. the attribute name is not in the correct context (it should be extendedAttributes.foo2)

both of which would be solved with this, if I understand correctly.

(there’s also the issue of property names in errors not being normalized too, but that’s outside of scope here, might even be API Platform specific)

Having the normalizer be able to provide a compatible violation list would allow API platform to render this case regardless what subsystem produced the error (serializer or validator).

WDYT? /cc @dunglas

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 21 (15 by maintainers)

Most upvoted comments

I think this is yet another use case for #38472.

I think @dunglas misunderstood my point:

@dunglas I’m not talking about adding violations specifically, but instead of having an opportunity to.

So, if I wanted to have serializer errors behave the same way as validation errors, I should be able to do that (since the behaviour is directly reflected in my APIP based apps to API users, it’s not “behind the scenes”).

After all, that’s the core point of this issue, the other thing was a bug.