Skip to content

Commit 115cf92

Browse files
authored
Merge pull request #3096 from teohhanhui/revert-3079
Revert #3079
2 parents 0e61379 + 8de3f81 commit 115cf92

File tree

10 files changed

+24
-193
lines changed

10 files changed

+24
-193
lines changed

features/main/operation.feature

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,3 @@ Feature: Operation support
5555
}
5656
}
5757
"""
58-
59-
Scenario: Get the collection of a resource that doesn't have a defined item operation
60-
When I send a "GET" request to "/disable_item_operations"
61-
Then the response status code should be 200
62-
63-
Scenario: Do not get a resource that doesn't have a defined item operation
64-
When I send a "GET" request to "/disable_item_operations/1"
65-
Then the response status code should be 404

src/Action/NotFoundAction.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/Bridge/Symfony/Bundle/Resources/config/api.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,6 @@
229229
<service id="api_platform.action.put_item" alias="api_platform.action.placeholder" public="true" />
230230
<service id="api_platform.action.delete_item" alias="api_platform.action.placeholder" public="true" />
231231
<service id="api_platform.action.get_subresource" alias="api_platform.action.placeholder" public="true" />
232-
<service id="api_platform.action.not_found" class="ApiPlatform\Core\Action\NotFoundAction" public="true" />
233-
<service id="ApiPlatform\Core\Action\NotFoundAction" alias="api_platform.action.not_found" public="true" />
234232

235233
<service id="api_platform.action.entrypoint" class="ApiPlatform\Core\Action\EntrypointAction" public="true">
236234
<argument type="service" id="api_platform.metadata.resource.name_collection_factory" />

src/JsonSchema/SchemaFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ private function getMetadata(string $resourceClass, string $type = Schema::TYPE_
230230
$inputOrOutput = $resourceMetadata->getTypedOperationAttribute($operationType, $operationName, $attribute, ['class' => $resourceClass], true);
231231
}
232232

233-
if (false === ($inputOrOutput['class'] ?? false)) {
233+
if (null === ($inputOrOutput['class'] ?? null)) {
234234
// input or output disabled
235235
return null;
236236
}

src/Metadata/Resource/Factory/OperationResourceMetadataFactory.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace ApiPlatform\Core\Metadata\Resource\Factory;
1515

16-
use ApiPlatform\Core\Action\NotFoundAction;
1716
use ApiPlatform\Core\Metadata\Resource\ResourceMetadata;
1817

1918
/**
@@ -82,13 +81,6 @@ public function create(string $resourceClass): ResourceMetadata
8281
$resourceMetadata = $this->normalize(false, $resourceClass, $resourceMetadata, $itemOperations);
8382
}
8483

85-
if ($this->needsDefaultGetOperation($resourceMetadata)) {
86-
$resourceMetadata = $resourceMetadata->withItemOperations(array_merge(
87-
$resourceMetadata->getItemOperations(),
88-
['get' => ['method' => 'GET', 'read' => false, 'output' => ['class' => false], 'controller' => NotFoundAction::class]])
89-
);
90-
}
91-
9284
$graphql = $resourceMetadata->getGraphql();
9385
if (null === $graphql) {
9486
$resourceMetadata = $resourceMetadata->withGraphql(['item_query' => [], 'collection_query' => [], 'delete' => [], 'update' => [], 'create' => []]);
@@ -156,17 +148,4 @@ private function normalizeGraphQl(ResourceMetadata $resourceMetadata, array $ope
156148

157149
return $resourceMetadata->withGraphql($operations);
158150
}
159-
160-
private function needsDefaultGetOperation(ResourceMetadata $resourceMetadata): bool
161-
{
162-
$itemOperations = $resourceMetadata->getItemOperations();
163-
164-
foreach ($itemOperations as $itemOperation) {
165-
if ('GET' === ($itemOperation['method'] ?? false)) {
166-
return false;
167-
}
168-
}
169-
170-
return true;
171-
}
172151
}

tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace ApiPlatform\Core\Tests\Bridge\Symfony\Bundle\DependencyInjection;
1515

16-
use ApiPlatform\Core\Action\NotFoundAction;
1716
use ApiPlatform\Core\Api\FilterInterface;
1817
use ApiPlatform\Core\Api\IdentifiersExtractorInterface;
1918
use ApiPlatform\Core\Api\IriConverterInterface;
@@ -844,7 +843,6 @@ private function getPartialContainerBuilderProphecy()
844843
'api_platform.action.documentation',
845844
'api_platform.action.entrypoint',
846845
'api_platform.action.exception',
847-
'api_platform.action.not_found',
848846
'api_platform.action.placeholder',
849847
'api_platform.cache.identifiers_extractor',
850848
'api_platform.cache.metadata.property',
@@ -940,24 +938,23 @@ private function getPartialContainerBuilderProphecy()
940938
'api_platform.property_accessor' => 'property_accessor',
941939
'api_platform.property_info' => 'property_info',
942940
'api_platform.serializer' => 'serializer',
943-
CollectionDataProviderInterface::class => 'api_platform.collection_data_provider',
944-
DataPersisterInterface::class => 'api_platform.data_persister',
945-
GroupFilter::class => 'api_platform.serializer.group_filter',
946-
IdentifiersExtractorInterface::class => 'api_platform.identifiers_extractor.cached',
941+
Pagination::class => 'api_platform.pagination',
947942
IriConverterInterface::class => 'api_platform.iri_converter',
943+
UrlGeneratorInterface::class => 'api_platform.router',
944+
SerializerContextBuilderInterface::class => 'api_platform.serializer.context_builder',
945+
CollectionDataProviderInterface::class => 'api_platform.collection_data_provider',
948946
ItemDataProviderInterface::class => 'api_platform.item_data_provider',
949-
NotFoundAction::class => 'api_platform.action.not_found',
950-
OperationAwareFormatsProviderInterface::class => 'api_platform.formats_provider',
951-
Pagination::class => 'api_platform.pagination',
952-
PropertyFilter::class => 'api_platform.serializer.property_filter',
947+
SubresourceDataProviderInterface::class => 'api_platform.subresource_data_provider',
948+
DataPersisterInterface::class => 'api_platform.data_persister',
949+
ResourceNameCollectionFactoryInterface::class => 'api_platform.metadata.resource.name_collection_factory',
950+
ResourceMetadataFactoryInterface::class => 'api_platform.metadata.resource.metadata_factory',
953951
PropertyNameCollectionFactoryInterface::class => 'api_platform.metadata.property.name_collection_factory',
954952
PropertyMetadataFactoryInterface::class => 'api_platform.metadata.property.metadata_factory',
955953
ResourceClassResolverInterface::class => 'api_platform.resource_class_resolver',
956-
ResourceNameCollectionFactoryInterface::class => 'api_platform.metadata.resource.name_collection_factory',
957-
ResourceMetadataFactoryInterface::class => 'api_platform.metadata.resource.metadata_factory',
958-
SerializerContextBuilderInterface::class => 'api_platform.serializer.context_builder',
959-
SubresourceDataProviderInterface::class => 'api_platform.subresource_data_provider',
960-
UrlGeneratorInterface::class => 'api_platform.router',
954+
PropertyFilter::class => 'api_platform.serializer.property_filter',
955+
GroupFilter::class => 'api_platform.serializer.group_filter',
956+
OperationAwareFormatsProviderInterface::class => 'api_platform.formats_provider',
957+
IdentifiersExtractorInterface::class => 'api_platform.identifiers_extractor.cached',
961958
];
962959

963960
foreach ($aliases as $alias => $service) {

tests/Fixtures/TestBundle/Document/DisableItemOperation.php

Lines changed: 0 additions & 45 deletions
This file was deleted.

tests/Fixtures/TestBundle/Entity/DisableItemOperation.php

Lines changed: 0 additions & 49 deletions
This file was deleted.

tests/JsonSchema/Command/JsonSchemaGenerateCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function testExecuteWithTooManyOptions()
6868
{
6969
$this->tester->run(['command' => 'api:json-schema:generate', 'resource' => $this->entityClass, '--collectionOperation' => 'get', '--itemOperation' => 'get', '--type' => 'output']);
7070

71-
$this->assertStringStartsWith('[ERROR] You can only use one of "--itemOperation" and "--collectionOperation" options at the same time.', trim(preg_replace('/\s+/', ' ', $this->tester->getDisplay())));
71+
$this->assertStringStartsWith('[ERROR] You can only use one of "--itemOperation" and "--collectionOperation"', trim(str_replace(["\r", "\n"], '', $this->tester->getDisplay())));
7272
}
7373

7474
public function testExecuteWithJsonldFormatOption()

tests/Metadata/Resource/Factory/OperationResourceMetadataFactoryTest.php

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
namespace ApiPlatform\Core\Tests\Metadata\Resource\Factory;
1515

16-
use ApiPlatform\Core\Action\NotFoundAction;
17-
use ApiPlatform\Core\Api\OperationType;
1816
use ApiPlatform\Core\Metadata\Resource\Factory\OperationResourceMetadataFactory;
1917
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
2018
use ApiPlatform\Core\Metadata\Resource\ResourceMetadata;
@@ -45,39 +43,29 @@ public function getMetadata(): iterable
4543
yield [new ResourceMetadata(null, null, null, null, [], null, [], []), new ResourceMetadata(null, null, null, $this->getOperations(['get', 'put', 'delete']), [], null, [], [])];
4644
yield [new ResourceMetadata(null, null, null, null, [], null, [], []), new ResourceMetadata(null, null, null, $this->getOperations(['get', 'put', 'patch', 'delete']), [], null, [], []), $jsonapi];
4745
yield [new ResourceMetadata(null, null, null, ['get'], [], null, [], []), new ResourceMetadata(null, null, null, $this->getOperations(['get']), [], null, [], [])];
48-
yield [new ResourceMetadata(null, null, null, [], [], null, [], []), new ResourceMetadata(null, null, null, $this->getPlaceholderOperation(), [], null, [], [])];
4946
yield [new ResourceMetadata(null, null, null, ['put'], [], null, [], []), new ResourceMetadata(null, null, null, $this->getOperations(['put']), [], null, [], [])];
5047
yield [new ResourceMetadata(null, null, null, ['delete'], [], null, [], []), new ResourceMetadata(null, null, null, $this->getOperations(['delete']), [], null, [], [])];
51-
yield [new ResourceMetadata(null, null, null, ['patch' => ['method' => 'PATCH', 'route_name' => 'patch']], [], null, [], []), new ResourceMetadata(null, null, null, array_merge(['patch' => ['method' => 'PATCH', 'route_name' => 'patch']], $this->getPlaceholderOperation()), [], null, [], [])];
52-
yield [new ResourceMetadata(null, null, null, ['patch' => ['method' => 'PATCH', 'route_name' => 'patch']], [], null, [], []), new ResourceMetadata(null, null, null, array_merge(['patch' => ['method' => 'PATCH', 'route_name' => 'patch']], $this->getPlaceholderOperation()), [], null, [], []), $jsonapi];
48+
yield [new ResourceMetadata(null, null, null, ['patch' => ['method' => 'PATCH', 'route_name' => 'patch']], [], null, [], []), new ResourceMetadata(null, null, null, ['patch' => ['method' => 'PATCH', 'route_name' => 'patch']], [], null, [], [])];
49+
yield [new ResourceMetadata(null, null, null, ['patch' => ['method' => 'PATCH', 'route_name' => 'patch']], [], null, [], []), new ResourceMetadata(null, null, null, ['patch' => ['method' => 'PATCH', 'route_name' => 'patch']], [], null, [], []), $jsonapi];
5350
yield [new ResourceMetadata(null, null, null, ['untouched' => ['method' => 'GET']], [], null, [], []), new ResourceMetadata(null, null, null, ['untouched' => ['method' => 'GET']], [], null, [], []), $jsonapi];
54-
yield [new ResourceMetadata(null, null, null, ['untouched_custom' => ['route_name' => 'custom_route']], [], null, [], []), new ResourceMetadata(null, null, null, array_merge(['untouched_custom' => ['route_name' => 'custom_route']], $this->getPlaceholderOperation()), [], null, [], []), $jsonapi];
51+
yield [new ResourceMetadata(null, null, null, ['untouched_custom' => ['route_name' => 'custom_route']], [], null, [], []), new ResourceMetadata(null, null, null, ['untouched_custom' => ['route_name' => 'custom_route']], [], null, [], []), $jsonapi];
5552

5653
// Collection operations
57-
yield [new ResourceMetadata(null, null, null, [], null, null, [], []), new ResourceMetadata(null, null, null, $this->getPlaceholderOperation(), $this->getOperations(['get', 'post'], OperationType::COLLECTION), null, [], [])];
58-
yield [new ResourceMetadata(null, null, null, [], ['get'], null, [], []), new ResourceMetadata(null, null, null, $this->getPlaceholderOperation(), $this->getOperations(['get'], OperationType::COLLECTION), null, [], [])];
59-
yield [new ResourceMetadata(null, null, null, [], ['post'], null, [], []), new ResourceMetadata(null, null, null, $this->getPlaceholderOperation(), $this->getOperations(['post'], OperationType::COLLECTION), null, [], [])];
60-
yield [new ResourceMetadata(null, null, null, [], ['options' => ['method' => 'OPTIONS', 'route_name' => 'options']], null, [], []), new ResourceMetadata(null, null, null, $this->getPlaceholderOperation(), ['options' => ['route_name' => 'options', 'method' => 'OPTIONS']], null, [], [])];
61-
yield [new ResourceMetadata(null, null, null, [], ['untouched' => ['method' => 'GET']], null, [], []), new ResourceMetadata(null, null, null, $this->getPlaceholderOperation(), ['untouched' => ['method' => 'GET']], null, [], [])];
62-
yield [new ResourceMetadata(null, null, null, [], ['untouched_custom' => ['route_name' => 'custom_route']], null, [], []), new ResourceMetadata(null, null, null, $this->getPlaceholderOperation(), ['untouched_custom' => ['route_name' => 'custom_route']], null, [], [])];
54+
yield [new ResourceMetadata(null, null, null, [], null, null, [], []), new ResourceMetadata(null, null, null, [], $this->getOperations(['get', 'post']), null, [], [])];
55+
yield [new ResourceMetadata(null, null, null, [], ['get'], null, [], []), new ResourceMetadata(null, null, null, [], $this->getOperations(['get']), null, [], [])];
56+
yield [new ResourceMetadata(null, null, null, [], ['post'], null, [], []), new ResourceMetadata(null, null, null, [], $this->getOperations(['post']), null, [], [])];
57+
yield [new ResourceMetadata(null, null, null, [], ['options' => ['method' => 'OPTIONS', 'route_name' => 'options']], null, [], []), new ResourceMetadata(null, null, null, [], ['options' => ['route_name' => 'options', 'method' => 'OPTIONS']], null, [], [])];
58+
yield [new ResourceMetadata(null, null, null, [], ['untouched' => ['method' => 'GET']], null, [], []), new ResourceMetadata(null, null, null, [], ['untouched' => ['method' => 'GET']], null, [], [])];
59+
yield [new ResourceMetadata(null, null, null, [], ['untouched_custom' => ['route_name' => 'custom_route']], null, [], []), new ResourceMetadata(null, null, null, [], ['untouched_custom' => ['route_name' => 'custom_route']], null, [], [])];
6360
}
6461

65-
private function getOperations(array $names, $operationType = OperationType::ITEM): array
62+
private function getOperations(array $names): array
6663
{
6764
$operations = [];
6865
foreach ($names as $name) {
6966
$operations[$name] = ['method' => strtoupper($name)];
7067
}
7168

72-
if (OperationType::ITEM === $operationType && !isset($operations['get'])) {
73-
return array_merge($operations, $this->getPlaceholderOperation());
74-
}
75-
7669
return $operations;
7770
}
78-
79-
private function getPlaceholderOperation(): array
80-
{
81-
return ['get' => ['method' => 'GET', 'read' => false, 'output' => ['class' => false], 'controller' => NotFoundAction::class]];
82-
}
8371
}

0 commit comments

Comments
 (0)