15
15
16
16
use ApiPlatform \Tests \Fixtures \TestBundle \Document \Dummy as DocumentDummy ;
17
17
use ApiPlatform \Tests \Fixtures \TestBundle \Entity \Dummy ;
18
+ use Symfony \Bridge \PhpUnit \ExpectDeprecationTrait ;
18
19
use Symfony \Bundle \FrameworkBundle \Console \Application ;
19
20
use Symfony \Bundle \FrameworkBundle \Test \KernelTestCase ;
20
21
use Symfony \Component \Console \Tester \ApplicationTester ;
24
25
*/
25
26
class JsonSchemaGenerateCommandTest extends KernelTestCase
26
27
{
28
+ use ExpectDeprecationTrait;
27
29
private ApplicationTester $ tester ;
28
30
29
31
private string $ entityClass ;
@@ -76,9 +78,9 @@ public function testExecuteWithJsonldTypeInput(): void
76
78
$ this ->tester ->run (['command ' => 'api:json-schema:generate ' , 'resource ' => $ this ->entityClass , '--operation ' => '_api_/dummies{._format}_post ' , '--format ' => 'jsonld ' , '--type ' => 'input ' ]);
77
79
$ result = $ this ->tester ->getDisplay ();
78
80
79
- $ this ->assertStringContainsString ('@id ' , $ result );
80
- $ this ->assertStringContainsString ('@context ' , $ result );
81
- $ this ->assertStringContainsString ('@type ' , $ result );
81
+ $ this ->assertStringNotContainsString ('@id ' , $ result );
82
+ $ this ->assertStringNotContainsString ('@context ' , $ result );
83
+ $ this ->assertStringNotContainsString ('@type ' , $ result );
82
84
}
83
85
84
86
/**
@@ -103,24 +105,24 @@ public function testArraySchemaWithReference(): void
103
105
$ result = $ this ->tester ->getDisplay ();
104
106
$ json = json_decode ($ result , associative: true );
105
107
106
- $ this ->assertEquals ($ json ['definitions ' ]['BagOfTests.jsonld-write.input ' ]['properties ' ]['tests ' ], [
108
+ $ this ->assertEquals ($ json ['definitions ' ]['BagOfTests.jsonld-write ' ]['properties ' ]['tests ' ], [
107
109
'type ' => 'string ' ,
108
110
'foo ' => 'bar ' ,
109
111
]);
110
112
111
- $ this ->assertEquals ($ json ['definitions ' ]['BagOfTests.jsonld-write.input ' ]['properties ' ]['nonResourceTests ' ], [
113
+ $ this ->assertEquals ($ json ['definitions ' ]['BagOfTests.jsonld-write ' ]['properties ' ]['nonResourceTests ' ], [
112
114
'type ' => 'array ' ,
113
115
'items ' => [
114
- '$ref ' => '#/definitions/NonResourceTestEntity.jsonld-write.input ' ,
116
+ '$ref ' => '#/definitions/NonResourceTestEntity.jsonld-write ' ,
115
117
],
116
118
]);
117
119
118
- $ this ->assertEquals ($ json ['definitions ' ]['BagOfTests.jsonld-write.input ' ]['properties ' ]['description ' ], [
120
+ $ this ->assertEquals ($ json ['definitions ' ]['BagOfTests.jsonld-write ' ]['properties ' ]['description ' ], [
119
121
'maxLength ' => 255 ,
120
122
]);
121
123
122
- $ this ->assertEquals ($ json ['definitions ' ]['BagOfTests.jsonld-write.input ' ]['properties ' ]['type ' ], [
123
- '$ref ' => '#/definitions/TestEntity.jsonld-write.input ' ,
124
+ $ this ->assertEquals ($ json ['definitions ' ]['BagOfTests.jsonld-write ' ]['properties ' ]['type ' ], [
125
+ '$ref ' => '#/definitions/TestEntity.jsonld-write ' ,
124
126
]);
125
127
}
126
128
@@ -130,14 +132,14 @@ public function testArraySchemaWithMultipleUnionTypesJsonLd(): void
130
132
$ result = $ this ->tester ->getDisplay ();
131
133
$ json = json_decode ($ result , associative: true );
132
134
133
- $ this ->assertEquals ($ json ['definitions ' ]['Nest.jsonld.output ' ]['properties ' ]['owner ' ]['anyOf ' ], [
134
- ['$ref ' => '#/definitions/Wren.jsonld.output ' ],
135
- ['$ref ' => '#/definitions/Robin.jsonld.output ' ],
135
+ $ this ->assertEquals ($ json ['definitions ' ]['Nest.jsonld ' ]['properties ' ]['owner ' ]['anyOf ' ], [
136
+ ['$ref ' => '#/definitions/Wren.jsonld ' ],
137
+ ['$ref ' => '#/definitions/Robin.jsonld ' ],
136
138
['type ' => 'null ' ],
137
139
]);
138
140
139
- $ this ->assertArrayHasKey ('Wren.jsonld.output ' , $ json ['definitions ' ]);
140
- $ this ->assertArrayHasKey ('Robin.jsonld.output ' , $ json ['definitions ' ]);
141
+ $ this ->assertArrayHasKey ('Wren.jsonld ' , $ json ['definitions ' ]);
142
+ $ this ->assertArrayHasKey ('Robin.jsonld ' , $ json ['definitions ' ]);
141
143
}
142
144
143
145
public function testArraySchemaWithMultipleUnionTypesJsonApi (): void
@@ -183,7 +185,7 @@ public function testArraySchemaWithTypeFactory(): void
183
185
$ result = $ this ->tester ->getDisplay ();
184
186
$ json = json_decode ($ result , associative: true );
185
187
186
- $ this ->assertEquals ($ json ['definitions ' ]['Foo.jsonld.output ' ]['properties ' ]['expiration ' ], ['type ' => 'string ' , 'format ' => 'date ' ]);
188
+ $ this ->assertEquals ($ json ['definitions ' ]['Foo.jsonld ' ]['properties ' ]['expiration ' ], ['type ' => 'string ' , 'format ' => 'date ' ]);
187
189
}
188
190
189
191
/**
@@ -195,7 +197,7 @@ public function testWritableNonResourceRef(): void
195
197
$ result = $ this ->tester ->getDisplay ();
196
198
$ json = json_decode ($ result , associative: true );
197
199
198
- $ this ->assertEquals ($ json ['definitions ' ]['SaveProduct.jsonld.input ' ]['properties ' ]['codes ' ]['items ' ]['$ref ' ], '#/definitions/ProductCode.jsonld.input ' );
200
+ $ this ->assertEquals ($ json ['definitions ' ]['SaveProduct.jsonld ' ]['properties ' ]['codes ' ]['items ' ]['$ref ' ], '#/definitions/ProductCode.jsonld ' );
199
201
}
200
202
201
203
/**
@@ -207,8 +209,8 @@ public function testOpenApiResourceRefIsNotOverwritten(): void
207
209
$ result = $ this ->tester ->getDisplay ();
208
210
$ json = json_decode ($ result , associative: true );
209
211
210
- $ this ->assertEquals ('#/definitions/DummyFriend ' , $ json ['definitions ' ]['Issue6299.Issue6299OutputDto.jsonld.output ' ]['properties ' ]['itemDto ' ]['$ref ' ]);
211
- $ this ->assertEquals ('#/definitions/DummyDate ' , $ json ['definitions ' ]['Issue6299.Issue6299OutputDto.jsonld.output ' ]['properties ' ]['collectionDto ' ]['items ' ]['$ref ' ]);
212
+ $ this ->assertEquals ('#/definitions/DummyFriend ' , $ json ['definitions ' ]['Issue6299.Issue6299OutputDto.jsonld ' ]['properties ' ]['itemDto ' ]['$ref ' ]);
213
+ $ this ->assertEquals ('#/definitions/DummyDate ' , $ json ['definitions ' ]['Issue6299.Issue6299OutputDto.jsonld ' ]['properties ' ]['collectionDto ' ]['items ' ]['$ref ' ]);
212
214
}
213
215
214
216
/**
@@ -220,7 +222,7 @@ public function testSubSchemaJsonLd(): void
220
222
$ result = $ this ->tester ->getDisplay ();
221
223
$ json = json_decode ($ result , associative: true );
222
224
223
- $ this ->assertArrayHasKey ('@id ' , $ json ['definitions ' ]['ThirdLevel.jsonld-friends.output ' ]['properties ' ]);
225
+ $ this ->assertArrayHasKey ('@id ' , $ json ['definitions ' ]['ThirdLevel.jsonld-friends ' ]['properties ' ]);
224
226
}
225
227
226
228
public function testJsonApiIncludesSchema (): void
@@ -332,4 +334,17 @@ public function testResourceWithEnumPropertiesSchema(): void
332
334
$ properties ['genders ' ]
333
335
);
334
336
}
337
+
338
+ /**
339
+ * @group legacy
340
+ * TODO: find a way to keep required properties if needed
341
+ */
342
+ public function testPatchSchemaRequiredProperties (): void
343
+ {
344
+ $ this ->tester ->run (['command ' => 'api:json-schema:generate ' , 'resource ' => 'ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\PatchRequired\PatchMe ' , '--format ' => 'json ' ]);
345
+ $ result = $ this ->tester ->getDisplay ();
346
+ $ json = json_decode ($ result , associative: true );
347
+
348
+ $ this ->assertEquals (['b ' ], $ json ['definitions ' ]['PatchMe ' ]['required ' ]);
349
+ }
335
350
}
0 commit comments