-
-
Notifications
You must be signed in to change notification settings - Fork 958
fix(state): object mapper with input different #7435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the API Platform project. | ||
| * | ||
| * (c) Kévin Dunglas <dunglas@gmail.com> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource; | ||
|
|
||
| use ApiPlatform\Doctrine\Orm\State\Options; | ||
| use ApiPlatform\JsonLd\ContextBuilder; | ||
| use ApiPlatform\Metadata\Operation; | ||
| use ApiPlatform\Metadata\Post; | ||
| use ApiPlatform\Tests\Fixtures\TestBundle\Dto\MappedResouceInput; | ||
| use ApiPlatform\Tests\Fixtures\TestBundle\Entity\MappedEntity; | ||
| use Symfony\Component\ObjectMapper\Attribute\Map; | ||
|
|
||
| #[Post( | ||
| uriTemplate: '/mapped_resource_with_input', | ||
| input: MappedResouceInput::class, | ||
| stateOptions: new Options(entityClass: MappedEntity::class), | ||
| normalizationContext: [ContextBuilder::HYDRA_CONTEXT_HAS_PREFIX => false], | ||
| processor: [self::class, 'process'] | ||
| )] | ||
| #[Map(target: MappedEntity::class)] | ||
| final class MappedResourceWithInput | ||
| { | ||
| #[Map(if: false)] | ||
| public ?string $id = null; | ||
| public string $username; | ||
|
|
||
| public static function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []) | ||
| { | ||
| $s = new self(); | ||
| $s->id = $data->id; | ||
| $s->username = $data->name; | ||
|
|
||
| return $s; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the API Platform project. | ||
| * | ||
| * (c) Kévin Dunglas <dunglas@gmail.com> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace ApiPlatform\Tests\Fixtures\TestBundle\Dto; | ||
|
|
||
| class MappedResouceInput | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe also add a test where both these fields are required in the input's constructor, and with coverage on
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what brings this test to the mapping functionality ? |
||
| { | ||
| public string $id; | ||
| public string $name; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part (writing a value with a name different from it's input name) might only be possible since ObjectMapper's last patch release, and might break pre-7.3.4. Maybe cover this in the composer.json conflicts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I've an issue with this le'ts talk about this at #7504