Skip to content

Commit

Permalink
Merge pull request #3397 from api-platform/revert-3362-fix/type-facto…
Browse files Browse the repository at this point in the history
…ry-readblelink

Revert "fix getClassType with no readableLink"
  • Loading branch information
teohhanhui committed Feb 18, 2020
2 parents 21145c7 + 328eafd commit bba9fc4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
14 changes: 5 additions & 9 deletions src/JsonSchema/TypeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,11 @@ private function getClassType(?string $className, string $format = 'json', ?bool
return ['type' => 'string'];
}

if (true !== $readableLink) {
if ($this->isResourceClass($className)) {
return [
'type' => 'string',
'format' => 'iri-reference',
];
}

return ['type' => 'string'];
if ($this->isResourceClass($className) && true !== $readableLink) {
return [
'type' => 'string',
'format' => 'iri-reference',
];
}

$version = $schema->getVersion();
Expand Down
12 changes: 0 additions & 12 deletions tests/JsonSchema/TypeFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Dummy;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Ramsey\Uuid\Uuid;
use Symfony\Component\PropertyInfo\Type;

class TypeFactoryTest extends TestCase
Expand All @@ -40,21 +39,10 @@ public function typeProvider(): iterable
yield [['type' => 'boolean'], new Type(Type::BUILTIN_TYPE_BOOL)];
yield [['type' => 'string'], new Type(Type::BUILTIN_TYPE_OBJECT)];
yield [['type' => 'string', 'format' => 'date-time'], new Type(Type::BUILTIN_TYPE_OBJECT, false, \DateTimeImmutable::class)];
yield [['type' => 'string', 'format' => 'uuid'], new Type(Type::BUILTIN_TYPE_OBJECT, false, Uuid::class)];
yield [['type' => 'string'], new Type(Type::BUILTIN_TYPE_OBJECT, false, Dummy::class)];
yield [['type' => 'array', 'items' => ['type' => 'string']], new Type(Type::BUILTIN_TYPE_STRING, false, null, true)];
}

public function testGetTypeWithSchema(): void
{
$typeFactory = new TypeFactory();
$type = new Type(Type::BUILTIN_TYPE_OBJECT, false, Dummy::class);
$this->assertSame(
['type' => 'string', 'format' => 'iri-reference'],
$typeFactory->getType($type, 'json', null, null, new Schema())
);
}

public function testGetClassType(): void
{
$schemaFactoryProphecy = $this->prophesize(SchemaFactoryInterface::class);
Expand Down

0 comments on commit bba9fc4

Please sign in to comment.