Skip to content

Commit fcc70fa

Browse files
authored
Merge pull request #1124 from soyuka/fix/1122
Swagger documentation normalizer revert throw when method is not supp…
2 parents a6307b2 + 52c6ba8 commit fcc70fa

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

src/Swagger/Serializer/DocumentationNormalizer.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use ApiPlatform\Core\Api\ResourceClassResolverInterface;
1919
use ApiPlatform\Core\Api\UrlGeneratorInterface;
2020
use ApiPlatform\Core\Documentation\Documentation;
21-
use ApiPlatform\Core\Exception\RuntimeException;
2221
use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
2322
use ApiPlatform\Core\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
2423
use ApiPlatform\Core\Metadata\Property\PropertyMetadata;
@@ -170,9 +169,9 @@ private function getPathOperation(string $operationName, array $operation, strin
170169
return $this->updatePutOperation($pathOperation, $mimeTypes, $collection, $resourceMetadata, $resourceClass, $resourceShortName, $operationName, $definitions);
171170
case 'DELETE':
172171
return $this->updateDeleteOperation($pathOperation, $resourceShortName);
173-
default:
174-
throw new RuntimeException(sprintf('Method "%s" is not supported', $method));
175172
}
173+
174+
return $pathOperation;
176175
}
177176

178177
/**

tests/Swagger/Serializer/DocumentationNormalizerTest.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,11 +1105,7 @@ public function testNoOperations()
11051105
$this->assertEquals($expected, $normalizer->normalize($documentation));
11061106
}
11071107

1108-
/**
1109-
* @expectedException \ApiPlatform\Core\Exception\RuntimeException
1110-
* @expectedMessage Method "foo" is not supported
1111-
*/
1112-
public function testMethodNotSupported()
1108+
public function testWithCustomMethod()
11131109
{
11141110
$documentation = new Documentation(new ResourceNameCollection([Dummy::class]), '', '', '0.0.0', ['jsonld' => ['application/ld+json']]);
11151111

@@ -1135,6 +1131,7 @@ public function testMethodNotSupported()
11351131
$operationMethodResolverProphecy->getCollectionOperationMethod(Dummy::class, 'get')->shouldBeCalled()->willReturn('FOO');
11361132

11371133
$urlGeneratorProphecy = $this->prophesize(UrlGeneratorInterface::class);
1134+
$urlGeneratorProphecy->generate('api_entrypoint')->willReturn('/')->shouldBeCalled();
11381135

11391136
$operationPathResolver = new CustomOperationPathResolver(new UnderscoreOperationPathResolver());
11401137

@@ -1148,7 +1145,24 @@ public function testMethodNotSupported()
11481145
$urlGeneratorProphecy->reveal()
11491146
);
11501147

1151-
$normalizer->normalize($documentation);
1148+
$expected = [
1149+
'swagger' => '2.0',
1150+
'basePath' => '/',
1151+
'info' => [
1152+
'title' => '',
1153+
'version' => '0.0.0',
1154+
],
1155+
'paths' => new \ArrayObject([
1156+
'/dummies' => [
1157+
'foo' => new \ArrayObject([
1158+
'tags' => ['Dummy'],
1159+
'operationId' => 'getDummyCollection',
1160+
]),
1161+
],
1162+
]),
1163+
];
1164+
1165+
$this->assertEquals($expected, $normalizer->normalize($documentation));
11521166
}
11531167

11541168
public function testNormalizeWithNestedNormalizationGroups()

0 commit comments

Comments
 (0)