Skip to content

Commit

Permalink
Merge 4379501 into 255b22f
Browse files Browse the repository at this point in the history
  • Loading branch information
Raulnet committed Jan 23, 2020
2 parents 255b22f + 4379501 commit 7584ffe
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/JsonSchema/TypeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,14 @@ private function getClassType(?string $className, string $format = 'json', ?bool
return ['type' => 'string'];
}

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

$version = $schema->getVersion();
Expand Down
15 changes: 15 additions & 0 deletions tests/JsonSchema/TypeFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@

namespace ApiPlatform\Core\Tests\JsonSchema;

use ApiPlatform\Core\Exception\ResourceClassNotFoundException;
use ApiPlatform\Core\JsonSchema\Schema;
use ApiPlatform\Core\JsonSchema\SchemaFactoryInterface;
use ApiPlatform\Core\JsonSchema\TypeFactory;
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
use ApiPlatform\Core\Metadata\Resource\ResourceMetadata;
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 @@ -39,10 +43,21 @@ 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 7584ffe

Please sign in to comment.