Skip to content

Commit

Permalink
fix(openapi): do not throw error with non standard HTTP verb (#4304)
Browse files Browse the repository at this point in the history
  • Loading branch information
qboot committed Jun 4, 2021
1 parent 6099c3d commit e32b4e8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/OpenApi/Factory/OpenApiFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use ApiPlatform\Core\Metadata\Resource\ResourceMetadata;
use ApiPlatform\Core\OpenApi\Model;
use ApiPlatform\Core\OpenApi\Model\ExternalDocumentation;
use ApiPlatform\Core\OpenApi\Model\PathItem;
use ApiPlatform\Core\OpenApi\OpenApi;
use ApiPlatform\Core\OpenApi\Options;
use ApiPlatform\Core\Operation\Factory\SubresourceOperationFactoryInterface;
Expand Down Expand Up @@ -144,6 +145,11 @@ private function collectPaths(ResourceMetadata $resourceMetadata, string $resour
$resourceClass = $operation['resource_class'] ?? $rootResourceClass;
$path = $this->getPath($resourceShortName, $operationName, $operation, $operationType);
$method = $resourceMetadata->getTypedOperationAttribute($operationType, $operationName, 'method', 'GET');

if (!\in_array($method, PathItem::$methods, true)) {
continue;
}

[$requestMimeTypes, $responseMimeTypes] = $this->getMimeTypes($resourceClass, $operationName, $operationType, $resourceMetadata);
$operationId = $operation['openapi_context']['operationId'] ?? lcfirst($operationName).ucfirst($resourceShortName).ucfirst($operationType);
$linkedOperationId = 'get'.ucfirst($resourceShortName).ucfirst(OperationType::ITEM);
Expand Down
2 changes: 1 addition & 1 deletion src/OpenApi/Model/PathItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class PathItem
{
use ExtensionTrait;

private static $methods = ['GET', 'PUT', 'POST', 'DELETE', 'OPTIONS', 'HEAD', 'PATCH', 'TRACE'];
public static $methods = ['GET', 'PUT', 'POST', 'DELETE', 'OPTIONS', 'HEAD', 'PATCH', 'TRACE'];
private $ref;
private $summary;
private $description;
Expand Down
1 change: 1 addition & 0 deletions tests/OpenApi/Factory/OpenApiFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public function testInvoke(): void
],
],
]] + self::OPERATION_FORMATS,
'custom-http-verb' => ['method' => 'TEST'] + self::OPERATION_FORMATS,
'formats' => ['method' => 'PUT', 'path' => '/formatted/{id}', 'output_formats' => ['json' => ['application/json'], 'csv' => ['text/csv']], 'input_formats' => ['json' => ['application/json'], 'csv' => ['text/csv']]],
],
[
Expand Down

0 comments on commit e32b4e8

Please sign in to comment.