Skip to content

Commit

Permalink
Merge edcf4da into 837dc48
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Feb 2, 2021
2 parents 837dc48 + edcf4da commit 34cb7ed
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/OpenApi/Serializer/OpenApiNormalizer.php
Expand Up @@ -54,9 +54,14 @@ private function recursiveClean($data): array
continue;
}

if ('schemas' === $key) {
ksort($value);
}

// Side effect of using getPaths(): Paths which itself contains the array
if ('paths' === $key) {
$value = $data['paths'] = $data['paths']['paths'];
ksort($value);
unset($data['paths']['paths']);
}

Expand Down
22 changes: 21 additions & 1 deletion tests/OpenApi/Serializer/OpenApiNormalizerTest.php
Expand Up @@ -53,10 +53,11 @@ class OpenApiNormalizerTest extends TestCase
public function testNormalize()
{
$resourceNameCollectionFactoryProphecy = $this->prophesize(ResourceNameCollectionFactoryInterface::class);
$resourceNameCollectionFactoryProphecy->create()->shouldBeCalled()->willReturn(new ResourceNameCollection([Dummy::class]));
$resourceNameCollectionFactoryProphecy->create()->shouldBeCalled()->willReturn(new ResourceNameCollection([Dummy::class, 'Zorro']));
$defaultContext = ['base_url' => '/app_dev.php/'];
$propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
$propertyNameCollectionFactoryProphecy->create(Dummy::class, Argument::any())->shouldBeCalled()->willReturn(new PropertyNameCollection(['id', 'name', 'description', 'dummyDate']));
$propertyNameCollectionFactoryProphecy->create('Zorro', Argument::any())->shouldBeCalled()->willReturn(new PropertyNameCollection(['id']));

$dummyMetadata = new ResourceMetadata(
'Dummy',
Expand All @@ -74,18 +75,34 @@ public function testNormalize()
[]
);

$zorroMetadata = new ResourceMetadata(
'Zorro',
'This is zorro.',
'http://schema.example.com/Zorro',
[
'get' => ['method' => 'GET'] + self::OPERATION_FORMATS,
],
[
'get' => ['method' => 'GET'] + self::OPERATION_FORMATS,
],
[]
);

$subresourceOperationFactoryProphecy = $this->prophesize(SubresourceOperationFactoryInterface::class);
$subresourceOperationFactoryProphecy->create(Argument::any(), Argument::any(), Argument::any())->willReturn([]);

$resourceMetadataFactoryProphecy = $this->prophesize(ResourceMetadataFactoryInterface::class);
$resourceMetadataFactoryProphecy->create(Dummy::class)->shouldBeCalled()->willReturn($dummyMetadata);
$resourceMetadataFactoryProphecy->create('Zorro')->shouldBeCalled()->willReturn($zorroMetadata);

$propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
$propertyMetadataFactoryProphecy->create(Dummy::class, 'id', Argument::any())->shouldBeCalled()->willReturn(new PropertyMetadata(new Type(Type::BUILTIN_TYPE_INT), 'This is an id.', true, false, null, null, null, true, null, null, null, null, null, null, null, ['minLength' => 3, 'maxLength' => 20, 'pattern' => '^dummyPattern$']));
$propertyMetadataFactoryProphecy->create(Dummy::class, 'name', Argument::any())->shouldBeCalled()->willReturn(new PropertyMetadata(new Type(Type::BUILTIN_TYPE_STRING), 'This is a name.', true, true, true, true, false, false, null, null, [], null, null, null, null));
$propertyMetadataFactoryProphecy->create(Dummy::class, 'description', Argument::any())->shouldBeCalled()->willReturn(new PropertyMetadata(new Type(Type::BUILTIN_TYPE_STRING), 'This is an initializable but not writable property.', true, false, true, true, false, false, null, null, [], null, true));
$propertyMetadataFactoryProphecy->create(Dummy::class, 'dummyDate', Argument::any())->shouldBeCalled()->willReturn(new PropertyMetadata(new Type(Type::BUILTIN_TYPE_OBJECT, true, \DateTime::class), 'This is a \DateTimeInterface object.', true, true, true, true, false, false, null, null, []));

$propertyMetadataFactoryProphecy->create('Zorro', 'id', Argument::any())->shouldBeCalled()->willReturn(new PropertyMetadata(new Type(Type::BUILTIN_TYPE_INT), 'This is an id.', true, false, null, null, null, true));

$operationPathResolver = new CustomOperationPathResolver(new OperationPathResolver(new UnderscorePathSegmentNameGenerator()));
$filterLocatorProphecy = $this->prophesize(ContainerInterface::class);
$resourceMetadataFactory = $resourceMetadataFactoryProphecy->reveal();
Expand Down Expand Up @@ -165,5 +182,8 @@ public function testNormalize()
// Security can be disabled per-operation using an empty array
$this->assertEquals([], $openApiAsArray['paths']['/dummies']['post']['security']);
$this->assertEquals(['url' => '/test'], $openApiAsArray['paths']['/dummies']['post']['servers']);

// Make sure things are sorted
$this->assertEquals(array_keys($openApiAsArray['paths']), ['/dummies', '/dummies/{id}', '/zorros', '/zorros/{id}']);
}
}

0 comments on commit 34cb7ed

Please sign in to comment.