Skip to content

Commit e32b4e8

Browse files
authored
fix(openapi): do not throw error with non standard HTTP verb (#4304)
1 parent 6099c3d commit e32b4e8

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

src/OpenApi/Factory/OpenApiFactory.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use ApiPlatform\Core\Metadata\Resource\ResourceMetadata;
2828
use ApiPlatform\Core\OpenApi\Model;
2929
use ApiPlatform\Core\OpenApi\Model\ExternalDocumentation;
30+
use ApiPlatform\Core\OpenApi\Model\PathItem;
3031
use ApiPlatform\Core\OpenApi\OpenApi;
3132
use ApiPlatform\Core\OpenApi\Options;
3233
use ApiPlatform\Core\Operation\Factory\SubresourceOperationFactoryInterface;
@@ -144,6 +145,11 @@ private function collectPaths(ResourceMetadata $resourceMetadata, string $resour
144145
$resourceClass = $operation['resource_class'] ?? $rootResourceClass;
145146
$path = $this->getPath($resourceShortName, $operationName, $operation, $operationType);
146147
$method = $resourceMetadata->getTypedOperationAttribute($operationType, $operationName, 'method', 'GET');
148+
149+
if (!\in_array($method, PathItem::$methods, true)) {
150+
continue;
151+
}
152+
147153
[$requestMimeTypes, $responseMimeTypes] = $this->getMimeTypes($resourceClass, $operationName, $operationType, $resourceMetadata);
148154
$operationId = $operation['openapi_context']['operationId'] ?? lcfirst($operationName).ucfirst($resourceShortName).ucfirst($operationType);
149155
$linkedOperationId = 'get'.ucfirst($resourceShortName).ucfirst(OperationType::ITEM);

src/OpenApi/Model/PathItem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ final class PathItem
1717
{
1818
use ExtensionTrait;
1919

20-
private static $methods = ['GET', 'PUT', 'POST', 'DELETE', 'OPTIONS', 'HEAD', 'PATCH', 'TRACE'];
20+
public static $methods = ['GET', 'PUT', 'POST', 'DELETE', 'OPTIONS', 'HEAD', 'PATCH', 'TRACE'];
2121
private $ref;
2222
private $summary;
2323
private $description;

tests/OpenApi/Factory/OpenApiFactoryTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public function testInvoke(): void
118118
],
119119
],
120120
]] + self::OPERATION_FORMATS,
121+
'custom-http-verb' => ['method' => 'TEST'] + self::OPERATION_FORMATS,
121122
'formats' => ['method' => 'PUT', 'path' => '/formatted/{id}', 'output_formats' => ['json' => ['application/json'], 'csv' => ['text/csv']], 'input_formats' => ['json' => ['application/json'], 'csv' => ['text/csv']]],
122123
],
123124
[

0 commit comments

Comments
 (0)