api-platform / api-platform/core

DTO as resource - auto convert subresource identifiers to objects

Open
#8,094 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
2.6k
Forks
980
Avg merge
2d 4h
Merged PRs (30d)
49

Description

Hi,

I've created subresource. This resource is DTO, not an entity.

```php
#[ApiResource(
operations: [
new Post(
uriTemplate: '/events/{eventId}/participants/{participantId}/images.{_format}',
uriVariables: [
# possible bug below
'eventId' => new Link(fromClass: EventResource::class, toProperty: 'event'),
'participantId' => new Link(fromClass: EventParticipantResource::class, toProperty: 'participant'),
],
processor: CreateEventParticipantImageProcessor::class,
),
/** ... */
readonly class EventParticipantImageResource
```

Problem is that in `CreateEventParticipantImageProcessor` I can use only uri variables cause query is not serialized:
```php
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []) {
$eventId = $uriVariables['eventId']; # identifier
$eventId = $data->event?->id; # null
}
```

Is there functionality that will convert identifiers to target resources and assign to DTO fields so I can use `$data->event?->id`?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.