1919use ApiPlatform \JsonSchema \Tests \Fixtures \ApiResource \OverriddenOperationDummy ;
2020use ApiPlatform \JsonSchema \Tests \Fixtures \DummyResourceInterface ;
2121use ApiPlatform \JsonSchema \Tests \Fixtures \Enum \GenderTypeEnum ;
22+ use ApiPlatform \JsonSchema \Tests \Fixtures \GenericChild ;
2223use ApiPlatform \JsonSchema \Tests \Fixtures \NotAResource ;
2324use ApiPlatform \JsonSchema \Tests \Fixtures \NotAResourceWithUnionIntersectTypes ;
2425use ApiPlatform \JsonSchema \Tests \Fixtures \Serializable ;
@@ -126,7 +127,7 @@ public function testBuildSchemaForNonResourceClass(): void
126127 $ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataCollectionFactoryInterface::class);
127128
128129 $ propertyNameCollectionFactoryProphecy = $ this ->prophesize (PropertyNameCollectionFactoryInterface::class);
129- $ propertyNameCollectionFactoryProphecy ->create (NotAResource::class, Argument::cetera ())->willReturn (new PropertyNameCollection (['foo ' , 'bar ' , 'genderType ' ]));
130+ $ propertyNameCollectionFactoryProphecy ->create (NotAResource::class, Argument::cetera ())->willReturn (new PropertyNameCollection (['foo ' , 'bar ' , 'genderType ' , ' items ' ]));
130131
131132 $ propertyMetadataFactoryProphecy = $ this ->prophesize (PropertyMetadataFactoryInterface::class);
132133 $ propertyMetadataFactoryProphecy ->create (NotAResource::class, 'foo ' , Argument::cetera ())->willReturn (
@@ -150,9 +151,28 @@ public function testBuildSchemaForNonResourceClass(): void
150151 ->withDefault ('male ' )
151152 ->withSchema (['type ' => 'object ' , 'default ' => 'male ' , 'example ' => 'male ' ])
152153 );
154+ $ propertyMetadataFactoryProphecy ->create (NotAResource::class, 'items ' , Argument::cetera ())->willReturn (
155+ (new ApiProperty ())
156+ ->withNativeType (
157+ Type::generic (Type::object (GenericChild::class), Type::int ()),
158+ )
159+ ->withReadable (true )
160+ ->withSchema (['type ' => Schema::UNKNOWN_TYPE ])
161+ );
162+
163+ $ propertyNameCollectionFactoryProphecy ->create (GenericChild::class, Argument::cetera ())
164+ ->willReturn (new PropertyNameCollection (['property ' ]));
165+ $ propertyMetadataFactoryProphecy ->create (GenericChild::class, 'property ' , Argument::cetera ())
166+ ->willReturn (
167+ (new ApiProperty ())
168+ ->withNativeType (Type::string ())
169+ ->withReadable (true )
170+ ->withSchema (['type ' => 'string ' ])
171+ );
153172
154173 $ resourceClassResolverProphecy = $ this ->prophesize (ResourceClassResolverInterface::class);
155174 $ resourceClassResolverProphecy ->isResourceClass (NotAResource::class)->willReturn (false );
175+ $ resourceClassResolverProphecy ->isResourceClass (GenericChild::class)->willReturn (false );
156176
157177 $ definitionNameFactory = new DefinitionNameFactory ();
158178
@@ -194,6 +214,10 @@ public function testBuildSchemaForNonResourceClass(): void
194214 $ this ->assertSame ('object ' , $ definitions [$ rootDefinitionKey ]['properties ' ]['genderType ' ]['type ' ]);
195215 $ this ->assertSame ('male ' , $ definitions [$ rootDefinitionKey ]['properties ' ]['genderType ' ]['default ' ]);
196216 $ this ->assertSame ('male ' , $ definitions [$ rootDefinitionKey ]['properties ' ]['genderType ' ]['example ' ]);
217+
218+ $ this ->assertArrayHasKey ('items ' , $ definitions [$ rootDefinitionKey ]['properties ' ]);
219+ $ this ->assertArrayHasKey ('$ref ' , $ definitions [$ rootDefinitionKey ]['properties ' ]['items ' ]);
220+ $ this ->assertSame ('#/definitions/GenericChild ' , $ definitions [$ rootDefinitionKey ]['properties ' ]['items ' ]['$ref ' ]);
197221 }
198222
199223 #[IgnoreDeprecations]
0 commit comments