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 89622aa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 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
20 changes: 10 additions & 10 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 Expand Up @@ -266,11 +267,18 @@ public function testParseRelation()

$this->assertEquals([
'relatedDummy' => [
'dataType' => null,
'dataType' => 'IRI',
'required' => false,
'description' => 'A related dummy.',
'readonly' => false,
'actualType' => DataTypes::MODEL,
'actualType' => DataTypes::STRING,
],
'relatedDummies' => [
'dataType' => null,
'required' => false,
'description' => 'Several dummies.',
'readonly' => false,
'actualType' => DataTypes::COLLECTION,
'subType' => RelatedDummy::class,
'children' => [
'id' => [
Expand All @@ -287,14 +295,6 @@ public function testParseRelation()
],
],
],
'relatedDummies' => [
'dataType' => 'array of IRIs',
'required' => false,
'description' => 'Several dummies.',
'readonly' => false,
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::STRING,
],
], $actual);
}
}

0 comments on commit 89622aa

Please sign in to comment.