Description
Symfony version(s) affected
7.1.10
Description
Since #59134, DTO that changes type in a constructor is no longer accepted.
Trigger of this seem to be that in a given PR, disable_type_enforcement
no longer defaults to true. However, this might be a deeper issue, as thanks to type juggling in constructor there should not be any type mismatch in the first place. Notice that in reproducer, although (private) property is declared to be an array, constructor accepts string. Hence, denormalization should accept string.
I bet this is another issue of a kind in #46918, since serializer has no way to distinguish class property named same way as constructor parameter
How to reproduce
Query DTO:
readonly class ScimQueryInput
{
/** @var list<string> */
private array $attributes;
public function __construct(string $attributes = '') {
$this->attributes = $attributes ? explode(',', $attributes) : [];
}
public function isAttributeAllowed(string $attribute): bool
{
return !\in_array($attribute, $this->attributes, true);
}
}
Controller:
class GetUsersController
{
#[Route('/api/datasync/scim/{connectorId}/Users')]
public function __invoke(#[MapQueryString] ScimQueryInput $queryInput = new ScimQueryInput()): Response
{
return new Response();
}
}
Call: /api/datasync/scim/Users?attributes=displayName,userName
Response:
Current response status code is 404, but 200 expected. (Behat\Mink\Exception\ExpectationException)
│
│ {
│ "type": "https://symfony.com/errors/validation",
│ "title": "Validation Failed",
│ "detail": "attributes: This value should be of type array.",
│ "violations": [
│ {
│ "propertyPath": "attributes",
│ "title": "This value should be of type array.",
│ "template": "This value should be of type {{ type }}.",
│ "parameters": {
│ "{{ type }}": "array"
│ }
│ },
│ ]
│ }
Possible Solution
No response
Additional Context
No response