14
14
namespace ApiPlatform \JsonSchema \Tests \Metadata \Property \Factory ;
15
15
16
16
use ApiPlatform \JsonSchema \Metadata \Property \Factory \SchemaPropertyMetadataFactory ;
17
+ use ApiPlatform \JsonSchema \Tests \Fixtures \DummyWithCustomOpenApiContext ;
17
18
use ApiPlatform \JsonSchema \Tests \Fixtures \DummyWithEnum ;
18
19
use ApiPlatform \JsonSchema \Tests \Fixtures \Enum \IntEnumAsIdentifier ;
19
20
use ApiPlatform \Metadata \ApiProperty ;
@@ -34,4 +35,18 @@ public function testEnum(): void
34
35
$ apiProperty = $ schemaPropertyMetadataFactory ->create (DummyWithEnum::class, 'intEnumAsIdentifier ' );
35
36
$ this ->assertEquals (['type ' => ['integer ' , 'null ' ], 'enum ' => [1 , 2 , null ]], $ apiProperty ->getSchema ());
36
37
}
38
+
39
+ public function testWithCustomOpenApiContext (): void
40
+ {
41
+ $ resourceClassResolver = $ this ->createMock (ResourceClassResolverInterface::class);
42
+ $ apiProperty = new ApiProperty (
43
+ builtinTypes: [new Type (builtinType: 'object ' , nullable: true , class: IntEnumAsIdentifier::class)],
44
+ openapiContext: ['type ' => 'object ' , 'properties ' => ['alpha ' => ['type ' => 'integer ' ]]],
45
+ );
46
+ $ decorated = $ this ->createMock (PropertyMetadataFactoryInterface::class);
47
+ $ decorated ->expects ($ this ->once ())->method ('create ' )->with (DummyWithCustomOpenApiContext::class, 'acme ' )->willReturn ($ apiProperty );
48
+ $ schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory ($ resourceClassResolver , $ decorated );
49
+ $ apiProperty = $ schemaPropertyMetadataFactory ->create (DummyWithCustomOpenApiContext::class, 'acme ' );
50
+ $ this ->assertEquals ([], $ apiProperty ->getSchema ());
51
+ }
37
52
}
0 commit comments