Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions features/main/operation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,3 @@ Feature: Operation support
}
}
"""

Scenario: Get the collection of a resource that doesn't have a defined item operation
When I send a "GET" request to "/disable_item_operations"
Then the response status code should be 200

Scenario: Do not get a resource that doesn't have a defined item operation
When I send a "GET" request to "/disable_item_operations/1"
Then the response status code should be 404
29 changes: 0 additions & 29 deletions src/Action/NotFoundAction.php

This file was deleted.

2 changes: 0 additions & 2 deletions src/Bridge/Symfony/Bundle/Resources/config/api.xml
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,6 @@
<service id="api_platform.action.put_item" alias="api_platform.action.placeholder" public="true" />
<service id="api_platform.action.delete_item" alias="api_platform.action.placeholder" public="true" />
<service id="api_platform.action.get_subresource" alias="api_platform.action.placeholder" public="true" />
<service id="api_platform.action.not_found" class="ApiPlatform\Core\Action\NotFoundAction" public="true" />
<service id="ApiPlatform\Core\Action\NotFoundAction" alias="api_platform.action.not_found" public="true" />

<service id="api_platform.action.entrypoint" class="ApiPlatform\Core\Action\EntrypointAction" public="true">
<argument type="service" id="api_platform.metadata.resource.name_collection_factory" />
Expand Down
2 changes: 1 addition & 1 deletion src/JsonSchema/SchemaFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ private function getMetadata(string $resourceClass, string $type = Schema::TYPE_
$inputOrOutput = $resourceMetadata->getTypedOperationAttribute($operationType, $operationName, $attribute, ['class' => $resourceClass], true);
}

if (false === ($inputOrOutput['class'] ?? false)) {
if (null === ($inputOrOutput['class'] ?? null)) {
// input or output disabled
return null;
}
Expand Down
21 changes: 0 additions & 21 deletions src/Metadata/Resource/Factory/OperationResourceMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace ApiPlatform\Core\Metadata\Resource\Factory;

use ApiPlatform\Core\Action\NotFoundAction;
use ApiPlatform\Core\Metadata\Resource\ResourceMetadata;

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

if ($this->needsDefaultGetOperation($resourceMetadata)) {
$resourceMetadata = $resourceMetadata->withItemOperations(array_merge(
$resourceMetadata->getItemOperations(),
['get' => ['method' => 'GET', 'read' => false, 'output' => ['class' => false], 'controller' => NotFoundAction::class]])
);
}

$graphql = $resourceMetadata->getGraphql();
if (null === $graphql) {
$resourceMetadata = $resourceMetadata->withGraphql(['item_query' => [], 'collection_query' => [], 'delete' => [], 'update' => [], 'create' => []]);
Expand Down Expand Up @@ -156,17 +148,4 @@ private function normalizeGraphQl(ResourceMetadata $resourceMetadata, array $ope

return $resourceMetadata->withGraphql($operations);
}

private function needsDefaultGetOperation(ResourceMetadata $resourceMetadata): bool
{
$itemOperations = $resourceMetadata->getItemOperations();

foreach ($itemOperations as $itemOperation) {
if ('GET' === ($itemOperation['method'] ?? false)) {
return false;
}
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

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

use ApiPlatform\Core\Action\NotFoundAction;
use ApiPlatform\Core\Api\FilterInterface;
use ApiPlatform\Core\Api\IdentifiersExtractorInterface;
use ApiPlatform\Core\Api\IriConverterInterface;
Expand Down Expand Up @@ -844,7 +843,6 @@ private function getPartialContainerBuilderProphecy()
'api_platform.action.documentation',
'api_platform.action.entrypoint',
'api_platform.action.exception',
'api_platform.action.not_found',
'api_platform.action.placeholder',
'api_platform.cache.identifiers_extractor',
'api_platform.cache.metadata.property',
Expand Down Expand Up @@ -940,24 +938,23 @@ private function getPartialContainerBuilderProphecy()
'api_platform.property_accessor' => 'property_accessor',
'api_platform.property_info' => 'property_info',
'api_platform.serializer' => 'serializer',
CollectionDataProviderInterface::class => 'api_platform.collection_data_provider',
DataPersisterInterface::class => 'api_platform.data_persister',
GroupFilter::class => 'api_platform.serializer.group_filter',
IdentifiersExtractorInterface::class => 'api_platform.identifiers_extractor.cached',
Pagination::class => 'api_platform.pagination',
IriConverterInterface::class => 'api_platform.iri_converter',
UrlGeneratorInterface::class => 'api_platform.router',
SerializerContextBuilderInterface::class => 'api_platform.serializer.context_builder',
CollectionDataProviderInterface::class => 'api_platform.collection_data_provider',
ItemDataProviderInterface::class => 'api_platform.item_data_provider',
NotFoundAction::class => 'api_platform.action.not_found',
OperationAwareFormatsProviderInterface::class => 'api_platform.formats_provider',
Pagination::class => 'api_platform.pagination',
PropertyFilter::class => 'api_platform.serializer.property_filter',
SubresourceDataProviderInterface::class => 'api_platform.subresource_data_provider',
DataPersisterInterface::class => 'api_platform.data_persister',
ResourceNameCollectionFactoryInterface::class => 'api_platform.metadata.resource.name_collection_factory',
ResourceMetadataFactoryInterface::class => 'api_platform.metadata.resource.metadata_factory',
PropertyNameCollectionFactoryInterface::class => 'api_platform.metadata.property.name_collection_factory',
PropertyMetadataFactoryInterface::class => 'api_platform.metadata.property.metadata_factory',
ResourceClassResolverInterface::class => 'api_platform.resource_class_resolver',
ResourceNameCollectionFactoryInterface::class => 'api_platform.metadata.resource.name_collection_factory',
ResourceMetadataFactoryInterface::class => 'api_platform.metadata.resource.metadata_factory',
SerializerContextBuilderInterface::class => 'api_platform.serializer.context_builder',
SubresourceDataProviderInterface::class => 'api_platform.subresource_data_provider',
UrlGeneratorInterface::class => 'api_platform.router',
PropertyFilter::class => 'api_platform.serializer.property_filter',
GroupFilter::class => 'api_platform.serializer.group_filter',
OperationAwareFormatsProviderInterface::class => 'api_platform.formats_provider',
IdentifiersExtractorInterface::class => 'api_platform.identifiers_extractor.cached',
];

foreach ($aliases as $alias => $service) {
Expand Down
45 changes: 0 additions & 45 deletions tests/Fixtures/TestBundle/Document/DisableItemOperation.php

This file was deleted.

49 changes: 0 additions & 49 deletions tests/Fixtures/TestBundle/Entity/DisableItemOperation.php

This file was deleted.

2 changes: 1 addition & 1 deletion tests/JsonSchema/Command/JsonSchemaGenerateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function testExecuteWithTooManyOptions()
{
$this->tester->run(['command' => 'api:json-schema:generate', 'resource' => $this->entityClass, '--collectionOperation' => 'get', '--itemOperation' => 'get', '--type' => 'output']);

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

public function testExecuteWithJsonldFormatOption()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

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

use ApiPlatform\Core\Action\NotFoundAction;
use ApiPlatform\Core\Api\OperationType;
use ApiPlatform\Core\Metadata\Resource\Factory\OperationResourceMetadataFactory;
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
use ApiPlatform\Core\Metadata\Resource\ResourceMetadata;
Expand Down Expand Up @@ -45,39 +43,29 @@ public function getMetadata(): iterable
yield [new ResourceMetadata(null, null, null, null, [], null, [], []), new ResourceMetadata(null, null, null, $this->getOperations(['get', 'put', 'delete']), [], null, [], [])];
yield [new ResourceMetadata(null, null, null, null, [], null, [], []), new ResourceMetadata(null, null, null, $this->getOperations(['get', 'put', 'patch', 'delete']), [], null, [], []), $jsonapi];
yield [new ResourceMetadata(null, null, null, ['get'], [], null, [], []), new ResourceMetadata(null, null, null, $this->getOperations(['get']), [], null, [], [])];
yield [new ResourceMetadata(null, null, null, [], [], null, [], []), new ResourceMetadata(null, null, null, $this->getPlaceholderOperation(), [], null, [], [])];
yield [new ResourceMetadata(null, null, null, ['put'], [], null, [], []), new ResourceMetadata(null, null, null, $this->getOperations(['put']), [], null, [], [])];
yield [new ResourceMetadata(null, null, null, ['delete'], [], null, [], []), new ResourceMetadata(null, null, null, $this->getOperations(['delete']), [], null, [], [])];
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, [], [])];
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];
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, [], [])];
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];
yield [new ResourceMetadata(null, null, null, ['untouched' => ['method' => 'GET']], [], null, [], []), new ResourceMetadata(null, null, null, ['untouched' => ['method' => 'GET']], [], null, [], []), $jsonapi];
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];
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];

// Collection operations
yield [new ResourceMetadata(null, null, null, [], null, null, [], []), new ResourceMetadata(null, null, null, $this->getPlaceholderOperation(), $this->getOperations(['get', 'post'], OperationType::COLLECTION), null, [], [])];
yield [new ResourceMetadata(null, null, null, [], ['get'], null, [], []), new ResourceMetadata(null, null, null, $this->getPlaceholderOperation(), $this->getOperations(['get'], OperationType::COLLECTION), null, [], [])];
yield [new ResourceMetadata(null, null, null, [], ['post'], null, [], []), new ResourceMetadata(null, null, null, $this->getPlaceholderOperation(), $this->getOperations(['post'], OperationType::COLLECTION), null, [], [])];
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, [], [])];
yield [new ResourceMetadata(null, null, null, [], ['untouched' => ['method' => 'GET']], null, [], []), new ResourceMetadata(null, null, null, $this->getPlaceholderOperation(), ['untouched' => ['method' => 'GET']], null, [], [])];
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, [], [])];
yield [new ResourceMetadata(null, null, null, [], null, null, [], []), new ResourceMetadata(null, null, null, [], $this->getOperations(['get', 'post']), null, [], [])];
yield [new ResourceMetadata(null, null, null, [], ['get'], null, [], []), new ResourceMetadata(null, null, null, [], $this->getOperations(['get']), null, [], [])];
yield [new ResourceMetadata(null, null, null, [], ['post'], null, [], []), new ResourceMetadata(null, null, null, [], $this->getOperations(['post']), null, [], [])];
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, [], [])];
yield [new ResourceMetadata(null, null, null, [], ['untouched' => ['method' => 'GET']], null, [], []), new ResourceMetadata(null, null, null, [], ['untouched' => ['method' => 'GET']], null, [], [])];
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, [], [])];
}

private function getOperations(array $names, $operationType = OperationType::ITEM): array
private function getOperations(array $names): array
{
$operations = [];
foreach ($names as $name) {
$operations[$name] = ['method' => strtoupper($name)];
}

if (OperationType::ITEM === $operationType && !isset($operations['get'])) {
return array_merge($operations, $this->getPlaceholderOperation());
}

return $operations;
}

private function getPlaceholderOperation(): array
{
return ['get' => ['method' => 'GET', 'read' => false, 'output' => ['class' => false], 'controller' => NotFoundAction::class]];
}
}