Skip to content

Commit

Permalink
Fix data type for NelmioApiDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
teohhanhui committed Apr 12, 2016
1 parent 164f99b commit b88be25
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/Bridge/NelmioApiDoc/Parser/ApiPlatformParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ private function parseProperty(ResourceMetadata $resourceMetadata, PropertyMetad
}

$data['subType'] = $subProperty['subType'];
$data['children'] = $subProperty['children'];
if (isset($subProperty['children'])) {
$data['children'] = $subProperty['children'];
}
}

return $data;
Expand All @@ -186,9 +188,18 @@ private function parseProperty(ResourceMetadata $resourceMetadata, PropertyMetad
return $data;
}

try {
$this->resourceMetadataFactory->create($className);
} catch (ResourceClassNotFoundException $e) {
$data['actualType'] = DataTypes::MODEL;
$data['subType'] = $className;

return $data;
}

if (
(self::OUT_PREFIX === $io && $propertyMetadata->isReadableLink()) ||
(self::IN_PREFIX === $io && $propertyMetadata->isWritableLink())
(self::OUT_PREFIX === $io && !$propertyMetadata->isReadableLink()) ||
(self::IN_PREFIX === $io && !$propertyMetadata->isWritableLink())
) {
$data['dataType'] = self::TYPE_IRI;
$data['actualType'] = DataTypes::STRING;
Expand Down
1 change: 1 addition & 0 deletions tests/Bridge/NelmioApiDoc/Parser/ApiPlatformParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public function testParseRelation()
{
$resourceMetadataFactoryProphecy = $this->prophesize(ResourceMetadataFactoryInterface::class);
$resourceMetadataFactoryProphecy->create(Dummy::class)->willReturn(new ResourceMetadata())->shouldBeCalled();
$resourceMetadataFactoryProphecy->create(RelatedDummy::class)->willReturn(new ResourceMetadata())->shouldBeCalled();
$resourceMetadataFactory = $resourceMetadataFactoryProphecy->reveal();

$propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
Expand Down

0 comments on commit b88be25

Please sign in to comment.