Skip to content

Commit d267e57

Browse files
Fix review
1 parent ac0fc35 commit d267e57

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/Swagger/Serializer/ApiGatewayNormalizer.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
namespace ApiPlatform\Core\Swagger\Serializer;
1515

1616
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
17-
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
1817
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
1918

2019
/**
@@ -26,7 +25,7 @@
2625
*
2726
* @author Vincent Chalamon <[email protected]>
2827
*/
29-
final class ApiGatewayNormalizer implements ContextAwareNormalizerInterface, CacheableSupportsMethodInterface
28+
final class ApiGatewayNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface
3029
{
3130
const API_GATEWAY = 'api_gateway';
3231

@@ -44,8 +43,10 @@ public function __construct(NormalizerInterface $documentationNormalizer, $defau
4443
*/
4544
public function normalize($object, $format = null, array $context = [])
4645
{
47-
unset($context[self::API_GATEWAY]);
4846
$data = $this->documentationNormalizer->normalize($object, $format, $context);
47+
if (!($context[self::API_GATEWAY] ?? $this->defaultContext[self::API_GATEWAY])) {
48+
return $data;
49+
}
4950

5051
if (empty($data['basePath'])) {
5152
$data['basePath'] = '/';
@@ -108,9 +109,9 @@ public function normalize($object, $format = null, array $context = [])
108109
/**
109110
* {@inheritdoc}
110111
*/
111-
public function supportsNormalization($data, $format = null, array $context = [])
112+
public function supportsNormalization($data, $format = null)
112113
{
113-
return $this->documentationNormalizer->supportsNormalization($data, $format) && ($context[self::API_GATEWAY] ?? ($this->defaultContext[self::API_GATEWAY] ?? false));
114+
return $this->documentationNormalizer->supportsNormalization($data, $format);
114115
}
115116

116117
/**

tests/Swagger/Serializer/ApiGatewayNormalizerTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,21 @@ protected function setUp()
5151
public function testSupportsNormalization()
5252
{
5353
$this->documentationNormalizerMock->supportsNormalization('foo', 'bar')->willReturn(true)->shouldBeCalledTimes(1);
54-
$this->assertTrue($this->normalizer->supportsNormalization('foo', 'bar', ['api_gateway' => true]));
54+
$this->assertTrue($this->normalizer->supportsNormalization('foo', 'bar'));
5555
$this->assertTrue($this->normalizer->hasCacheableSupportsMethod());
5656
}
5757

58-
public function testItDoesNotSupportNormalizationWithoutApiGatewayContext()
58+
public function testNormalizeWithoutApiGateway()
5959
{
60-
$this->documentationNormalizerMock->supportsNormalization('foo', 'bar')->willReturn(true)->shouldBeCalledTimes(2);
61-
$this->assertFalse($this->normalizer->supportsNormalization('foo', 'bar', ['api_gateway' => false]));
62-
$this->assertFalse($this->normalizer->supportsNormalization('foo', 'bar'));
60+
$this->documentationNormalizerMock->normalize($this->objectMock, 'jsonld', [])
61+
->willReturn(['basePath' => '/api'])
62+
->shouldBeCalledTimes(1);
63+
$this->assertEquals(['basePath' => '/api'], $this->normalizer->normalize($this->objectMock->reveal(), 'jsonld'));
6364
}
6465

6566
public function testNormalizeWithApiGateway()
6667
{
67-
$this->documentationNormalizerMock->normalize($this->objectMock, 'jsonld', [])
68+
$this->documentationNormalizerMock->normalize($this->objectMock, 'jsonld', ['api_gateway' => true])
6869
->willReturn([
6970
'basePath' => '',
7071
'paths' => [

0 commit comments

Comments
 (0)