-
-
Notifications
You must be signed in to change notification settings - Fork 895
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(jsonschema): restore type factory usage (#5897)
fixes #5896
- Loading branch information
Showing
10 changed files
with
118 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ | |
/** | ||
* {@inheritdoc} | ||
* | ||
* @deprecated since 3.3 https://github.com/api-platform/core/pull/5470 | ||
* | ||
* @author Kévin Dunglas <[email protected]> | ||
*/ | ||
final class TypeFactory implements TypeFactoryInterface | ||
|
@@ -46,6 +48,11 @@ public function setSchemaFactory(SchemaFactoryInterface $schemaFactory): void | |
*/ | ||
public function getType(Type $type, string $format = 'json', bool $readableLink = null, array $serializerContext = null, Schema $schema = null): array | ||
{ | ||
if ('jsonschema' === $format) { | ||
return []; | ||
} | ||
|
||
// TODO: OpenApiFactory uses this to compute filter types | ||
if ($type->isCollection()) { | ||
$keyType = $type->getCollectionKeyTypes()[0] ?? null; | ||
$subType = ($type->getCollectionValueTypes()[0] ?? null) ?? new Type($type->getBuiltinType(), false, $type->getClassName(), false); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue5896; | ||
|
||
use ApiPlatform\Metadata\ApiProperty; | ||
use ApiPlatform\Metadata\Get; | ||
|
||
#[Get] | ||
class Foo | ||
{ | ||
#[ApiProperty(readable: false, writable: false, identifier: true)] | ||
public ?int $id = null; | ||
public ?LocalDate $expiration; | ||
} |
18 changes: 18 additions & 0 deletions
18
tests/Fixtures/TestBundle/ApiResource/Issue5896/LocalDate.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue5896; | ||
|
||
class LocalDate | ||
{ | ||
} |
38 changes: 38 additions & 0 deletions
38
tests/Fixtures/TestBundle/ApiResource/Issue5896/TypeFactoryDecorator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue5896; | ||
|
||
use ApiPlatform\JsonSchema\Schema; | ||
use ApiPlatform\JsonSchema\TypeFactoryInterface; | ||
use Symfony\Component\PropertyInfo\Type; | ||
|
||
class TypeFactoryDecorator implements TypeFactoryInterface | ||
{ | ||
public function __construct( | ||
private readonly TypeFactoryInterface $decorated, | ||
) { | ||
} | ||
|
||
public function getType(Type $type, string $format = 'json', bool $readableLink = null, array $serializerContext = null, Schema $schema = null): array | ||
{ | ||
if (is_a($type->getClassName(), LocalDate::class, true)) { | ||
return [ | ||
'type' => 'string', | ||
'format' => 'date', | ||
]; | ||
} | ||
|
||
return $this->decorated->getType($type, $format, $readableLink, $serializerContext, $schema); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters