19
19
use ApiPlatform \JsonSchema \Tests \Fixtures \ApiResource \OverriddenOperationDummy ;
20
20
use ApiPlatform \JsonSchema \Tests \Fixtures \DummyResourceInterface ;
21
21
use ApiPlatform \JsonSchema \Tests \Fixtures \Enum \GenderTypeEnum ;
22
+ use ApiPlatform \JsonSchema \Tests \Fixtures \GenericChild ;
22
23
use ApiPlatform \JsonSchema \Tests \Fixtures \NotAResource ;
23
24
use ApiPlatform \JsonSchema \Tests \Fixtures \NotAResourceWithUnionIntersectTypes ;
24
25
use ApiPlatform \JsonSchema \Tests \Fixtures \Serializable ;
@@ -126,7 +127,7 @@ public function testBuildSchemaForNonResourceClass(): void
126
127
$ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataCollectionFactoryInterface::class);
127
128
128
129
$ 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 ' ]));
130
131
131
132
$ propertyMetadataFactoryProphecy = $ this ->prophesize (PropertyMetadataFactoryInterface::class);
132
133
$ propertyMetadataFactoryProphecy ->create (NotAResource::class, 'foo ' , Argument::cetera ())->willReturn (
@@ -150,9 +151,28 @@ public function testBuildSchemaForNonResourceClass(): void
150
151
->withDefault ('male ' )
151
152
->withSchema (['type ' => 'object ' , 'default ' => 'male ' , 'example ' => 'male ' ])
152
153
);
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
+ );
153
172
154
173
$ resourceClassResolverProphecy = $ this ->prophesize (ResourceClassResolverInterface::class);
155
174
$ resourceClassResolverProphecy ->isResourceClass (NotAResource::class)->willReturn (false );
175
+ $ resourceClassResolverProphecy ->isResourceClass (GenericChild::class)->willReturn (false );
156
176
157
177
$ definitionNameFactory = new DefinitionNameFactory ();
158
178
@@ -194,6 +214,10 @@ public function testBuildSchemaForNonResourceClass(): void
194
214
$ this ->assertSame ('object ' , $ definitions [$ rootDefinitionKey ]['properties ' ]['genderType ' ]['type ' ]);
195
215
$ this ->assertSame ('male ' , $ definitions [$ rootDefinitionKey ]['properties ' ]['genderType ' ]['default ' ]);
196
216
$ 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 ' ]);
197
221
}
198
222
199
223
#[IgnoreDeprecations]
0 commit comments