core icon indicating copy to clipboard operation
core copied to clipboard

[Doctrine] Not include write operations for readonly entities

Open rvanlaak opened this issue 11 months ago • 3 comments

Description
Entities can be marked as readonly. The ApiResource operations could respect that, and by default not include the write-related operations.

Example

<?php

namespace App\Entity;

use ApiPlatform\Metadata\ApiResource;
use Doctrine\ORM\Mapping as ORM;

#[ApiResource]
#[ORM\Entity(readOnly: true)]
class Foo
{
    # ...
}

Actual

Image

Expected

Image

rvanlaak avatar Mar 14 '25 11:03 rvanlaak

This is a new feature?

https://github.com/api-platform/core/blob/main/src/Doctrine/Orm/Metadata/Resource/DoctrineOrmResourceCollectionMetadataFactory.php for reference to where to add this

soyuka avatar Mar 14 '25 15:03 soyuka

Curious whether or not this feature should be considered as a BC break, by not including write actions anymore. Another perspective; these entities already are readOnly, so probably don't allow any writes either way.

rvanlaak avatar Mar 14 '25 20:03 rvanlaak

For now you just need to specify the operations:

#[ApiResource(operations: [new Get(),  new GetCollection()])]

soyuka avatar Mar 16 '25 07:03 soyuka