Skip to content

Commit

Permalink
fix(doctrine): use stateOptions only within doctrine context (#5726)
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Aug 8, 2023
1 parent 78a4966 commit 7bb92a5
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 29 deletions.
30 changes: 26 additions & 4 deletions features/doctrine/separated_resource.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Feature: Use state options to use an entity that is not a resource

@!mongodb
@createSchema
Scenario: Get collection
Scenario: Get collection
Given there are 5 separated entities
When I send a "GET" request to "/separated_entities"
Then the response status code should be 200
Expand Down Expand Up @@ -35,7 +35,7 @@ Feature: Use state options to use an entity that is not a resource

@!mongodb
@createSchema
Scenario: Get ordered collection
Scenario: Get ordered collection
Given there are 5 separated entities
When I send a "GET" request to "/separated_entities?order[value]=desc"
Then the response status code should be 200
Expand All @@ -45,10 +45,32 @@ Feature: Use state options to use an entity that is not a resource

@!mongodb
@createSchema
Scenario: Get item
Scenario: Get item
Given there are 5 separated entities
When I send a "GET" request to "/separated_entities/1"
Then print last JSON response
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"

@!mongodb
@createSchema
Scenario: Get item
Given there are 5 separated entities
When I send a "GET" request to "/separated_entities/1"
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"

@!mongodb
@createSchema
Scenario: Get all EntityClassAndCustomProviderResources
Given there are 1 separated entities
When I send a "GET" request to "/entityClassAndCustomProviderResources"
Then the response status code should be 200

@!mongodb
@createSchema
Scenario: Get one EntityClassAndCustomProviderResource
Given there are 1 separated entities
When I send a "GET" request to "/entityClassAndCustomProviderResources/1"
Then the response status code should be 200
12 changes: 0 additions & 12 deletions features/main/crud_uri_variables.feature
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,3 @@ Feature: Uri Variables
When I add "Content-Type" header equal to "application/ld+json"
And I send a "GET" request to "/companies/1/employees/2"
Then the response status code should be 404

@!mongodb
Scenario: Get all EntityClassAndCustomProviderResources
Given there are 1 separated entities
When I send a "GET" request to "/entityClassAndCustomProviderResources"
Then the response status code should be 200

@!mongodb
Scenario: Get one EntityClassAndCustomProviderResource
Given there are 1 separated entities
When I send a "GET" request to "/entityClassAndCustomProviderResources/1"
Then the response status code should be 200
8 changes: 1 addition & 7 deletions src/Metadata/Resource/Factory/LinkFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace ApiPlatform\Metadata\Resource\Factory;

use ApiPlatform\Doctrine\Orm\State\Options;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Exception\RuntimeException;
use ApiPlatform\Metadata\Link;
Expand Down Expand Up @@ -59,12 +58,7 @@ public function createLinksFromIdentifiers(ApiResource|Operation $operation): ar
return [];
}

$entityClass = $resourceClass;
if (($options = $operation->getStateOptions()) && $options instanceof Options && $options->getEntityClass()) {
$entityClass = $options->getEntityClass();
}

$link = (new Link())->withFromClass($entityClass)->withIdentifiers($identifiers);
$link = (new Link())->withFromClass($resourceClass)->withIdentifiers($identifiers);
$parameterName = $identifiers[0];

if (1 < \count($identifiers)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource;

use ApiPlatform\Doctrine\Orm\State\Options;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
Expand All @@ -25,7 +24,6 @@
operations: [
new Get(
uriTemplate: '/entityClassAndCustomProviderResources/{id}',
uriVariables: ['id']
),
new GetCollection(
uriTemplate: '/entityClassAndCustomProviderResources'
Expand All @@ -36,8 +34,6 @@
)]
class EntityClassAndCustomProviderResource
{
#[ApiProperty(identifier: true)]
public ?int $id;

public ?string $value;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use ApiPlatform\Doctrine\Orm\State\CollectionProvider;
use ApiPlatform\Doctrine\Orm\State\ItemProvider;
use ApiPlatform\Doctrine\Orm\State\Options;
use ApiPlatform\Exception\ItemNotFoundException;
use ApiPlatform\Metadata\CollectionOperationInterface;
use ApiPlatform\Metadata\Operation;
Expand All @@ -39,7 +38,6 @@ public function __construct(
*/
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
{
$operation = ($stateOptions = $operation->getStateOptions()) instanceof Options ? $operation->withClass($stateOptions->getEntityClass()) : $operation;
if ($operation instanceof CollectionOperationInterface) {
$data = $this->collectionProvider->provide(
$operation,
Expand Down

0 comments on commit 7bb92a5

Please sign in to comment.