|
16 | 16 | use ApiPlatform\JsonSchema\Metadata\Property\Factory\SchemaPropertyMetadataFactory; |
17 | 17 | use ApiPlatform\JsonSchema\Tests\Fixtures\DummyWithCustomOpenApiContext; |
18 | 18 | use ApiPlatform\JsonSchema\Tests\Fixtures\DummyWithEnum; |
| 19 | +use ApiPlatform\JsonSchema\Tests\Fixtures\DummyWithMixed; |
19 | 20 | use ApiPlatform\JsonSchema\Tests\Fixtures\DummyWithUnionTypeProperty; |
20 | 21 | use ApiPlatform\JsonSchema\Tests\Fixtures\Enum\IntEnumAsIdentifier; |
21 | 22 | use ApiPlatform\Metadata\ApiProperty; |
@@ -167,4 +168,33 @@ public function testUnionTypeAnyOfIsArray(): void |
167 | 168 |
|
168 | 169 | $this->assertEquals($expectedSchema, $apiProperty->getSchema()); |
169 | 170 | } |
| 171 | + |
| 172 | + public function testMixed(): void |
| 173 | + { |
| 174 | + $resourceClassResolver = $this->createMock(ResourceClassResolverInterface::class); |
| 175 | + $apiProperty = new ApiProperty(nativeType: Type::mixed()); |
| 176 | + $decorated = $this->createMock(PropertyMetadataFactoryInterface::class); |
| 177 | + $decorated->expects($this->once())->method('create')->with(DummyWithMixed::class, 'mixedProperty')->willReturn($apiProperty); |
| 178 | + |
| 179 | + $schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory($resourceClassResolver, $decorated); |
| 180 | + $apiProperty = $schemaPropertyMetadataFactory->create(DummyWithMixed::class, 'mixedProperty'); |
| 181 | + |
| 182 | + $this->assertEquals([ |
| 183 | + 'type' => ['string', 'null'], |
| 184 | + ], $apiProperty->getSchema()); |
| 185 | + |
| 186 | + $apiProperty = new ApiProperty(nativeType: Type::array(Type::mixed())); |
| 187 | + $decorated = $this->createMock(PropertyMetadataFactoryInterface::class); |
| 188 | + $decorated->expects($this->once())->method('create')->with(DummyWithMixed::class, 'mixedArrayProperty')->willReturn($apiProperty); |
| 189 | + |
| 190 | + $schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory($resourceClassResolver, $decorated); |
| 191 | + $apiProperty = $schemaPropertyMetadataFactory->create(DummyWithMixed::class, 'mixedArrayProperty'); |
| 192 | + |
| 193 | + $this->assertEquals([ |
| 194 | + 'type' => 'array', |
| 195 | + 'items' => [ |
| 196 | + 'type' => ['string', 'null'], |
| 197 | + ], |
| 198 | + ], $apiProperty->getSchema()); |
| 199 | + } |
170 | 200 | } |
0 commit comments