|
19 | 19 | use ApiPlatform\Symfony\Bundle\Test\ApiTestCase; |
20 | 20 | use ApiPlatform\Symfony\Bundle\Test\Constraint\MatchesJsonSchema; |
21 | 21 | use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\AggregateRating; |
| 22 | +use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\ChildAttribute; |
22 | 23 | use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue5452\Book; |
23 | 24 | use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue5501\BrokenDocs; |
24 | 25 | use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue5501\Related; |
| 26 | +use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\ParentAttribute; |
25 | 27 | use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Product; |
26 | 28 | use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\ResourceWithEnumProperty; |
27 | 29 | use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Issue5793\BagOfTests; |
@@ -66,6 +68,8 @@ public static function getResources(): array |
66 | 68 | JsonSchemaResourceRelated::class, |
67 | 69 | Product::class, |
68 | 70 | AggregateRating::class, |
| 71 | + ParentAttribute::class, |
| 72 | + ChildAttribute::class, |
69 | 73 | ]; |
70 | 74 | } |
71 | 75 |
|
@@ -223,4 +227,33 @@ public function testGenIdFalse() |
223 | 227 | $schema = $this->schemaFactory->buildSchema(Product::class, 'jsonld', Schema::TYPE_OUTPUT, $this->operationMetadataFactory->create('_api_/json-stream-products_get_collection')); |
224 | 228 | $this->assertThat(['member' => [['aggregateRating' => ['ratingValue' => '1.0', 'reviewCount' => 1]]]], new MatchesJsonSchema($schema)); |
225 | 229 | } |
| 230 | + |
| 231 | + public function testSchemaWithAttributes(): void |
| 232 | + { |
| 233 | + $operation = $this->operationMetadataFactory->create('_api_/parent_attributes/{id}{._format}_get'); |
| 234 | + $context = $operation->getNormalizationContext() ?? []; |
| 235 | + |
| 236 | + $schema = $this->schemaFactory->buildSchema(ParentAttribute::class, 'json', Schema::TYPE_OUTPUT, $operation, null, $context); |
| 237 | + |
| 238 | + $parentDefinitionName = 'ParentAttribute-name_child.label'; |
| 239 | + $this->assertArrayHasKey($parentDefinitionName, $schema['definitions']); |
| 240 | + |
| 241 | + $parentProperties = $schema['definitions'][$parentDefinitionName]['properties']; |
| 242 | + |
| 243 | + $this->assertArrayHasKey('name', $parentProperties); |
| 244 | + $this->assertArrayHasKey('child', $parentProperties); |
| 245 | + |
| 246 | + $this->assertArrayNotHasKey('id', $parentProperties); |
| 247 | + $this->assertArrayNotHasKey('description', $parentProperties); |
| 248 | + |
| 249 | + $childDefinitionName = 'ChildAttribute-label'; |
| 250 | + $this->assertArrayHasKey($childDefinitionName, $schema['definitions']); |
| 251 | + |
| 252 | + $childProperties = $schema['definitions'][$childDefinitionName]['properties']; |
| 253 | + |
| 254 | + $this->assertArrayHasKey('label', $childProperties); |
| 255 | + |
| 256 | + $this->assertArrayNotHasKey('hiddenData', $childProperties); |
| 257 | + $this->assertArrayNotHasKey('id', $childProperties); |
| 258 | + } |
226 | 259 | } |
0 commit comments