From 52c6ba8f92c125a7280260374557a9edaedf1f40 Mon Sep 17 00:00:00 2001 From: abluchet Date: Wed, 17 May 2017 14:18:02 +0200 Subject: [PATCH] Swagger documentation normalizer revert throw when method is not supported --- .../Serializer/DocumentationNormalizer.php | 5 ++-- .../DocumentationNormalizerTest.php | 26 ++++++++++++++----- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/Swagger/Serializer/DocumentationNormalizer.php b/src/Swagger/Serializer/DocumentationNormalizer.php index 0c07d9f780a..b06fdfef6f2 100644 --- a/src/Swagger/Serializer/DocumentationNormalizer.php +++ b/src/Swagger/Serializer/DocumentationNormalizer.php @@ -18,7 +18,6 @@ use ApiPlatform\Core\Api\ResourceClassResolverInterface; use ApiPlatform\Core\Api\UrlGeneratorInterface; use ApiPlatform\Core\Documentation\Documentation; -use ApiPlatform\Core\Exception\RuntimeException; use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface; use ApiPlatform\Core\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface; use ApiPlatform\Core\Metadata\Property\PropertyMetadata; @@ -170,9 +169,9 @@ private function getPathOperation(string $operationName, array $operation, strin return $this->updatePutOperation($pathOperation, $mimeTypes, $collection, $resourceMetadata, $resourceClass, $resourceShortName, $operationName, $definitions); case 'DELETE': return $this->updateDeleteOperation($pathOperation, $resourceShortName); - default: - throw new RuntimeException(sprintf('Method "%s" is not supported', $method)); } + + return $pathOperation; } /** diff --git a/tests/Swagger/Serializer/DocumentationNormalizerTest.php b/tests/Swagger/Serializer/DocumentationNormalizerTest.php index 0e0bffd9bd4..778ae359257 100644 --- a/tests/Swagger/Serializer/DocumentationNormalizerTest.php +++ b/tests/Swagger/Serializer/DocumentationNormalizerTest.php @@ -1105,11 +1105,7 @@ public function testNoOperations() $this->assertEquals($expected, $normalizer->normalize($documentation)); } - /** - * @expectedException \ApiPlatform\Core\Exception\RuntimeException - * @expectedMessage Method "foo" is not supported - */ - public function testMethodNotSupported() + public function testWithCustomMethod() { $documentation = new Documentation(new ResourceNameCollection([Dummy::class]), '', '', '0.0.0', ['jsonld' => ['application/ld+json']]); @@ -1135,6 +1131,7 @@ public function testMethodNotSupported() $operationMethodResolverProphecy->getCollectionOperationMethod(Dummy::class, 'get')->shouldBeCalled()->willReturn('FOO'); $urlGeneratorProphecy = $this->prophesize(UrlGeneratorInterface::class); + $urlGeneratorProphecy->generate('api_entrypoint')->willReturn('/')->shouldBeCalled(); $operationPathResolver = new CustomOperationPathResolver(new UnderscoreOperationPathResolver()); @@ -1148,7 +1145,24 @@ public function testMethodNotSupported() $urlGeneratorProphecy->reveal() ); - $normalizer->normalize($documentation); + $expected = [ + 'swagger' => '2.0', + 'basePath' => '/', + 'info' => [ + 'title' => '', + 'version' => '0.0.0', + ], + 'paths' => new \ArrayObject([ + '/dummies' => [ + 'foo' => new \ArrayObject([ + 'tags' => ['Dummy'], + 'operationId' => 'getDummyCollection', + ]), + ], + ]), + ]; + + $this->assertEquals($expected, $normalizer->normalize($documentation)); } public function testNormalizeWithNestedNormalizationGroups()