File tree Expand file tree Collapse file tree 3 files changed +141
-0
lines changed Expand file tree Collapse file tree 3 files changed +141
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the API Platform project.
5
+ *
6
+ * (c) Kévin Dunglas <[email protected] >
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ declare (strict_types=1 );
13
+
14
+ namespace ApiPlatform \Tests \Fixtures \TestBundle \Document ;
15
+
16
+ use ApiPlatform \Core \Annotation \ApiProperty ;
17
+ use ApiPlatform \Core \Annotation \ApiResource ;
18
+ use Doctrine \ODM \MongoDB \Mapping \Annotations as ODM ;
19
+
20
+ /**
21
+ * JSON Schema Context Dummy.
22
+ *
23
+ * @ApiResource
24
+ *
25
+ * @ODM\Document
26
+ */
27
+ class JsonSchemaContextDummy
28
+ {
29
+ /**
30
+ * @var int The id
31
+ *
32
+ * @ApiProperty(identifier=true)
33
+ * @ODM\Id(strategy="INCREMENT", type="int")
34
+ */
35
+ private $ id ;
36
+
37
+ /**
38
+ * @var array
39
+ *
40
+ * @ApiProperty(
41
+ * attributes={
42
+ * "json_schema_context"={
43
+ * "type"="array",
44
+ * "items"={"type"="string"},
45
+ * "minItems"=2,
46
+ * "maxItems"=2
47
+ * }
48
+ * },
49
+ * )
50
+ */
51
+ private $ things = ['pool ' , 'bag ' ];
52
+
53
+ public function getId ()
54
+ {
55
+ return $ this ->id ;
56
+ }
57
+
58
+ public function getThings ()
59
+ {
60
+ return $ this ->things ;
61
+ }
62
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the API Platform project.
5
+ *
6
+ * (c) Kévin Dunglas <[email protected] >
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ declare (strict_types=1 );
13
+
14
+ namespace ApiPlatform \Tests \Fixtures \TestBundle \Entity ;
15
+
16
+ use ApiPlatform \Core \Annotation \ApiProperty ;
17
+ use ApiPlatform \Core \Annotation \ApiResource ;
18
+ use Doctrine \ORM \Mapping as ORM ;
19
+
20
+ /**
21
+ * JSON Schema Context Dummy.
22
+ *
23
+ * @ApiResource
24
+ *
25
+ * @ORM\Entity
26
+ */
27
+ class JsonSchemaContextDummy
28
+ {
29
+ /**
30
+ * @var int The id
31
+ *
32
+ * @ApiProperty(identifier=true)
33
+ * @ORM\Column(type="integer")
34
+ * @ORM\Id
35
+ * @ORM\GeneratedValue(strategy="AUTO")
36
+ */
37
+ private $ id ;
38
+
39
+ /**
40
+ * @var array
41
+ *
42
+ * @ApiProperty(
43
+ * attributes={
44
+ * "json_schema_context"={
45
+ * "type"="array",
46
+ * "items"={"type"="string"},
47
+ * "minItems"=2,
48
+ * "maxItems"=2
49
+ * }
50
+ * },
51
+ * )
52
+ */
53
+ private $ things = ['pool ' , 'bag ' ];
54
+
55
+ public function getId ()
56
+ {
57
+ return $ this ->id ;
58
+ }
59
+
60
+ public function getThings ()
61
+ {
62
+ return $ this ->things ;
63
+ }
64
+ }
Original file line number Diff line number Diff line change 17
17
use ApiPlatform \Tests \Fixtures \TestBundle \Document \Dummy as DummyDocument ;
18
18
use ApiPlatform \Tests \Fixtures \TestBundle \Entity \Dummy ;
19
19
use ApiPlatform \Tests \Fixtures \TestBundle \Entity \DummyDtoInputOutput ;
20
+ use ApiPlatform \Tests \Fixtures \TestBundle \Entity \JsonSchemaContextDummy ;
20
21
use ApiPlatform \Tests \Fixtures \TestBundle \Model \ResourceInterface ;
21
22
use Doctrine \ORM \EntityManagerInterface ;
22
23
use Doctrine \ORM \Tools \SchemaTool ;
@@ -141,6 +142,20 @@ public function testAssertMatchesResourceItemJsonSchema(): void
141
142
$ this ->assertMatchesResourceItemJsonSchema (ResourceInterface::class);
142
143
}
143
144
145
+ public function testAssertMatchesResourceItemJsonSchemaWithCustomJson (): void
146
+ {
147
+ $ this ->recreateSchema ();
148
+
149
+ /** @var EntityManagerInterface $manager */
150
+ $ manager = (method_exists (static ::class, 'getContainer ' ) ? static ::getContainer () : static ::$ container )->get ('doctrine ' )->getManager ();
151
+ $ jsonSchemaContextDummy = new JsonSchemaContextDummy ();
152
+ $ manager ->persist ($ jsonSchemaContextDummy );
153
+ $ manager ->flush ();
154
+
155
+ self ::createClient ()->request ('GET ' , '/json_schema_context_dummies/1 ' );
156
+ $ this ->assertMatchesResourceItemJsonSchema (JsonSchemaContextDummy::class);
157
+ }
158
+
144
159
public function testAssertMatchesResourceItemJsonSchemaOutput (): void
145
160
{
146
161
$ this ->recreateSchema ();
You can’t perform that action at this time.
0 commit comments