Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ private function getJsonSchemaFromType(Type $type, ?bool $readableLink = null):
TypeIdentifier::OBJECT => ['type' => 'object'],
TypeIdentifier::RESOURCE => ['type' => 'string'],
TypeIdentifier::CALLABLE => ['type' => 'string'],
TypeIdentifier::MIXED => ['type' => 'string'],
default => ['type' => 'null'],
};

Expand Down
23 changes: 23 additions & 0 deletions src/JsonSchema/Tests/Fixtures/DummyWithMixed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* 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\JsonSchema\Tests\Fixtures;

use ApiPlatform\Metadata\ApiResource;

#[ApiResource]
class DummyWithMixed
{
public mixed $mixedProperty;
public array $mixedArrayProperty;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use ApiPlatform\JsonSchema\Metadata\Property\Factory\SchemaPropertyMetadataFactory;
use ApiPlatform\JsonSchema\Tests\Fixtures\DummyWithCustomOpenApiContext;
use ApiPlatform\JsonSchema\Tests\Fixtures\DummyWithEnum;
use ApiPlatform\JsonSchema\Tests\Fixtures\DummyWithMixed;
use ApiPlatform\JsonSchema\Tests\Fixtures\DummyWithUnionTypeProperty;
use ApiPlatform\JsonSchema\Tests\Fixtures\Enum\IntEnumAsIdentifier;
use ApiPlatform\Metadata\ApiProperty;
Expand Down Expand Up @@ -167,4 +168,37 @@ public function testUnionTypeAnyOfIsArray(): void

$this->assertEquals($expectedSchema, $apiProperty->getSchema());
}

public function testMixed(): void
{
if (!method_exists(PropertyInfoExtractor::class, 'getType')) { // @phpstan-ignore-line symfony/property-info 6.4 is still allowed and this may be true
$this->markTestSkipped('This test only supports type-info component');
}

$resourceClassResolver = $this->createMock(ResourceClassResolverInterface::class);
$apiProperty = new ApiProperty(nativeType: Type::mixed());
$decorated = $this->createMock(PropertyMetadataFactoryInterface::class);
$decorated->expects($this->once())->method('create')->with(DummyWithMixed::class, 'mixedProperty')->willReturn($apiProperty);

$schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory($resourceClassResolver, $decorated);
$apiProperty = $schemaPropertyMetadataFactory->create(DummyWithMixed::class, 'mixedProperty');

$this->assertEquals([
'type' => ['string', 'null'],
], $apiProperty->getSchema());

$apiProperty = new ApiProperty(nativeType: Type::array(Type::mixed()));
$decorated = $this->createMock(PropertyMetadataFactoryInterface::class);
$decorated->expects($this->once())->method('create')->with(DummyWithMixed::class, 'mixedArrayProperty')->willReturn($apiProperty);

$schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory($resourceClassResolver, $decorated);
$apiProperty = $schemaPropertyMetadataFactory->create(DummyWithMixed::class, 'mixedArrayProperty');

$this->assertEquals([
'type' => 'array',
'items' => [
'type' => ['string', 'null'],
],
], $apiProperty->getSchema());
}
}
Loading