Skip to content

Commit bf1f930

Browse files
authored
Merge pull request #3362 from Raulnet/fix/type-factory-readblelink
fix getClassType with no readableLink
2 parents 255b22f + ed22824 commit bf1f930

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/JsonSchema/TypeFactory.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,15 @@ private function getClassType(?string $className, string $format = 'json', ?bool
9999
return ['type' => 'string'];
100100
}
101101

102-
if ($this->isResourceClass($className) && true !== $readableLink) {
103-
return [
104-
'type' => 'string',
105-
'format' => 'iri-reference',
106-
];
102+
if (true !== $readableLink) {
103+
if ($this->isResourceClass($className)) {
104+
return [
105+
'type' => 'string',
106+
'format' => 'iri-reference',
107+
];
108+
}
109+
110+
return ['type' => 'string'];
107111
}
108112

109113
$version = $schema->getVersion();

tests/JsonSchema/TypeFactoryTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Dummy;
2020
use PHPUnit\Framework\TestCase;
2121
use Prophecy\Argument;
22+
use Ramsey\Uuid\Uuid;
2223
use Symfony\Component\PropertyInfo\Type;
2324

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

48+
public function testGetTypeWithSchema(): void
49+
{
50+
$typeFactory = new TypeFactory();
51+
$type = new Type(Type::BUILTIN_TYPE_OBJECT, false, Dummy::class);
52+
$this->assertSame(
53+
['type' => 'string', 'format' => 'iri-reference'],
54+
$typeFactory->getType($type, 'json', null, null, new Schema())
55+
);
56+
}
57+
4658
public function testGetClassType(): void
4759
{
4860
$schemaFactoryProphecy = $this->prophesize(SchemaFactoryInterface::class);

0 commit comments

Comments
 (0)