-
-
Notifications
You must be signed in to change notification settings - Fork 137
Closed
Description
Since 0.19.2 it seems that prettier removes attributes, if an argument also has attributes that are more complex. See examples below. Especially relevant with PHP 8.2 setting and even newer prettier versions.
Not providing playground example as playground pretter plugin version is too old.
Might be related to: #2101
Prettier 2.8.8 However, also tried the latest prettier version with 0.21.0
PHP Plugin 0.19.6 However, also tried 0.19.2 and the latest 0.21.0 and to confirm it works with 0.19.1
# Options (if any):
--no-optionsInput:
<?php declare(strict_types=1);
namespace App\Controller\General;
use App\Dto\BarDto;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
class EnrollmentController extends AbstractController
{
#[Route(path: '/foo', name: 'app.foo', methods: Request::METHOD_POST)]
public function save(
#[
MapRequestPayload(
serializationContext: [
AbstractNormalizer::CALLBACKS => [
'abc' => 'trim',
],
],
),
]
BarDto $data,
): Response {
return $this->json(['foo']);
}
}Output:
<?php declare(strict_types=1);
namespace App\Controller\General;
use App\Dto\BarDto;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
class EnrollmentController extends AbstractController
{
public function save(
#[
MapRequestPayload(
serializationContext: [
AbstractNormalizer::CALLBACKS => [
'abc' => 'trim',
],
],
),
]
BarDto $data,
): Response {
return $this->json(['foo']);
}
}Expected behavior:
That the Route attribute is not removed but formatted accordingly.
What is interesting is that the following works fine, though code wise it is the same:
<?php declare(strict_types=1);
namespace App\Controller\General;
use App\Dto\BarDto;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
class EnrollmentController extends AbstractController
{
#[Route(path: '/foo', name: 'app.foo', methods: Request::METHOD_POST)]
public function save(
#[MapRequestPayload(serializationContext: [AbstractNormalizer::CALLBACKS => ['abc' => 'trim',],],), ]
BarDto $data,
): Response {
return $this->json(['foo']);
}
}Metadata
Metadata
Assignees
Labels
No labels