Skip to content

[Serializer] allow ObjectNormalizer to provide ConstraintViolationListInterface from ExtraAttributesException #25729

Closed
@dkarlovi

Description

@dkarlovi
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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions