You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working on an app that has apiplatform (currently migrating actually so a lot of my routes are still made with classic Symfony Controllers.
On one of them I tried to use the new MapRequestPayload attribute to hydrate a DTO and validate it. But in case there is a validation error, instead of having a nice "violations" array in my response, i get a weird 0:
class UserUpdateCredentialsDto
{
#[Assert\NotBlank]
#[Assert\Length(min: 6)]
#[AppAssert\EmailDns]
#[Groups(['update_credentials_all'])]
public ?string $email = null;
#[Assert\NotBlank]
#[Assert\Length(min: 6)]
#[Groups(['update_credentials_all'])]
public ?string $password = null;
#[SecurityAssert\UserPassword(
message: 'app.user.old_password.invalid',
)]
#[Groups(['update_credentials_all'])]
public ?string $oldPassword = null;
}
After a LOONG session of debugging I ended up finding the culprit for it : the apiplatform's ConstraintViolationListNormalizer
I still didn't figure out why it transforms the answers this way. I m haven't found anyone else who has the same problem as me so I guess soemthing's wrong with my app. Maybe the configuration of apiplatform ?
here s mine:
api_platform:
name_converter: 'Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter'
formats:
jsonapi: ['application/json']
json: ['application/json']
mapping:
paths: ['%kernel.project_dir%/src/Entity', '%kernel.project_dir%/src/Elastica/Document']
patch_formats:
json: ['application/merge-patch+json']
enable_swagger: false
enable_swagger_ui: false
enable_re_doc: false
enable_entrypoint: false
enable_docs: false
defaults:
normalization_context:
skip_null_values: false
pagination_enabled: true
pagination_client_enabled: true
pagination_items_per_page: 30 # Default value
pagination_client_items_per_page: true # Allow the client to request a different number of items per page
cache_headers:
max_age: 0 # Set 60 to reactivates cache
# shared_max_age: 3600
vary: [ 'Content-Type', 'Authorization', 'Origin' ]
invalidation:
xkey:
glue: ', '
collection:
pagination:
items_per_page_parameter_name: per_page
enabled_parameter_name: pagination # optional
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi !
I'm working on an app that has apiplatform (currently migrating actually so a lot of my routes are still made with classic Symfony Controllers.
On one of them I tried to use the new MapRequestPayload attribute to hydrate a DTO and validate it. But in case there is a validation error, instead of having a nice "violations" array in my response, i get a weird 0:
Here's the code of my controller:
and DTO:
After a LOONG session of debugging I ended up finding the culprit for it : the apiplatform's ConstraintViolationListNormalizer
I still didn't figure out why it transforms the answers this way. I m haven't found anyone else who has the same problem as me so I guess soemthing's wrong with my app. Maybe the configuration of apiplatform ?
here s mine:
Any help would be welcome... Thanks !
Beta Was this translation helpful? Give feedback.
All reactions