1616use ApiPlatform \JsonSchema \Metadata \Property \Factory \SchemaPropertyMetadataFactory ;
1717use ApiPlatform \JsonSchema \Tests \Fixtures \DummyWithCustomOpenApiContext ;
1818use ApiPlatform \JsonSchema \Tests \Fixtures \DummyWithEnum ;
19+ use ApiPlatform \JsonSchema \Tests \Fixtures \DummyWithUnionTypeProperty ;
1920use ApiPlatform \JsonSchema \Tests \Fixtures \Enum \IntEnumAsIdentifier ;
2021use ApiPlatform \Metadata \ApiProperty ;
2122use ApiPlatform \Metadata \Property \Factory \PropertyMetadataFactoryInterface ;
@@ -115,10 +116,11 @@ public function testWithCustomOpenApiContextWithoutTypeDefinitionLegacy(): void
115116 public function testWithCustomOpenApiContextWithoutTypeDefinition (): void
116117 {
117118 $ resourceClassResolver = $ this ->createMock (ResourceClassResolverInterface::class);
118- $ apiProperty = new ApiProperty (
119- openapiContext: ['description ' => 'My description ' ],
120- nativeType: Type::bool (),
121- );
119+ $ apiProperty =
120+ new ApiProperty (
121+ openapiContext: ['description ' => 'My description ' ],
122+ nativeType: Type::bool (),
123+ );
122124 $ decorated = $ this ->createMock (PropertyMetadataFactoryInterface::class);
123125 $ decorated ->expects ($ this ->once ())->method ('create ' )->with (DummyWithCustomOpenApiContext::class, 'foo ' )->willReturn ($ apiProperty );
124126 $ schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory ($ resourceClassResolver , $ decorated );
@@ -127,10 +129,11 @@ public function testWithCustomOpenApiContextWithoutTypeDefinition(): void
127129 'type ' => 'boolean ' ,
128130 ], $ apiProperty ->getSchema ());
129131
130- $ apiProperty = new ApiProperty (
131- openapiContext: ['iris ' => 'https://schema.org/Date ' ],
132- nativeType: Type::object (\DateTimeImmutable::class),
133- );
132+ $ apiProperty =
133+ new ApiProperty (
134+ openapiContext: ['iris ' => 'https://schema.org/Date ' ],
135+ nativeType: Type::object (\DateTimeImmutable::class),
136+ );
134137 $ decorated = $ this ->createMock (PropertyMetadataFactoryInterface::class);
135138 $ decorated ->expects ($ this ->once ())->method ('create ' )->with (DummyWithCustomOpenApiContext::class, 'bar ' )->willReturn ($ apiProperty );
136139 $ schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory ($ resourceClassResolver , $ decorated );
@@ -140,4 +143,24 @@ public function testWithCustomOpenApiContextWithoutTypeDefinition(): void
140143 'format ' => 'date-time ' ,
141144 ], $ apiProperty ->getSchema ());
142145 }
146+
147+ public function testUnionTypeAnyOfIsArray (): void
148+ {
149+ $ resourceClassResolver = $ this ->createMock (ResourceClassResolverInterface::class);
150+ $ apiProperty = new ApiProperty (nativeType: Type::union (Type::string (), Type::int ()));
151+ $ decorated = $ this ->createMock (PropertyMetadataFactoryInterface::class);
152+ $ decorated ->expects ($ this ->once ())->method ('create ' )->with (DummyWithUnionTypeProperty::class, 'unionProperty ' )->willReturn ($ apiProperty );
153+
154+ $ schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory ($ resourceClassResolver , $ decorated );
155+ $ apiProperty = $ schemaPropertyMetadataFactory ->create (DummyWithUnionTypeProperty::class, 'unionProperty ' );
156+
157+ $ expectedSchema = [
158+ 'anyOf ' => [
159+ ['type ' => 'integer ' ],
160+ ['type ' => 'string ' ],
161+ ],
162+ ];
163+
164+ $ this ->assertEquals ($ expectedSchema , $ apiProperty ->getSchema ());
165+ }
143166}
0 commit comments