|
14 | 14 | namespace ApiPlatform\Tests\Functional; |
15 | 15 |
|
16 | 16 | use ApiPlatform\Symfony\Bundle\Test\ApiTestCase; |
| 17 | +use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\ChildAttribute; |
17 | 18 | use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Crud; |
18 | 19 | use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\CrudOpenApiApiPlatformTag; |
19 | 20 | use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\DummyWebhook; |
20 | 21 | use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue6151\OverrideOpenApiResponses; |
| 22 | +use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\ParentAttribute; |
21 | 23 | use ApiPlatform\Tests\Fixtures\TestBundle\Entity\AbstractDummy; |
22 | 24 | use ApiPlatform\Tests\Fixtures\TestBundle\Entity\CircularReference; |
23 | 25 | use ApiPlatform\Tests\Fixtures\TestBundle\Entity\CompositeItem; |
@@ -100,6 +102,8 @@ public static function getResources(): array |
100 | 102 | JsonSchemaResource::class, |
101 | 103 | JsonSchemaResourceRelated::class, |
102 | 104 | WrappedResponseEntity::class, |
| 105 | + ParentAttribute::class, |
| 106 | + ChildAttribute::class, |
103 | 107 | ]; |
104 | 108 | } |
105 | 109 |
|
@@ -613,4 +617,36 @@ public function testRetrieveTheEntrypointWithUrlFormat(): void |
613 | 617 | $this->assertResponseHeaderSame('content-type', 'application/vnd.openapi+json; charset=utf-8'); |
614 | 618 | $this->assertJson($response->getContent()); |
615 | 619 | } |
| 620 | + |
| 621 | + public function testOpenApiSchemaWithNormalizationAttributes(): void |
| 622 | + { |
| 623 | + $response = self::createClient()->request('GET', '/docs', [ |
| 624 | + 'headers' => ['Accept' => 'application/vnd.openapi+json'], |
| 625 | + ]); |
| 626 | + $this->assertResponseIsSuccessful(); |
| 627 | + $json = $response->toArray(); |
| 628 | + |
| 629 | + $this->assertArrayHasKey('ParentAttribute-name_child.label', $json['components']['schemas']); |
| 630 | + $parentSchema = $json['components']['schemas']['ParentAttribute-name_child.label']; |
| 631 | + |
| 632 | + $this->assertArrayHasKey('properties', $parentSchema); |
| 633 | + $parentProperties = $parentSchema['properties']; |
| 634 | + |
| 635 | + $this->assertArrayHasKey('name', $parentProperties); |
| 636 | + $this->assertArrayHasKey('child', $parentProperties); |
| 637 | + |
| 638 | + $this->assertArrayNotHasKey('id', $parentProperties); |
| 639 | + $this->assertArrayNotHasKey('descriptionn', $parentProperties); |
| 640 | + |
| 641 | + $this->assertArrayHasKey('ChildAttribute-label', $json['components']['schemas']); |
| 642 | + $childSchema = $json['components']['schemas']['ChildAttribute-label']; |
| 643 | + |
| 644 | + $this->assertArrayHasKey('properties', $childSchema); |
| 645 | + $childProperties = $childSchema['properties']; |
| 646 | + |
| 647 | + $this->assertArrayHasKey('label', $childProperties); |
| 648 | + |
| 649 | + $this->assertArrayNotHasKey('hiddenData', $childProperties); |
| 650 | + $this->assertArrayNotHasKey('id', $childProperties); |
| 651 | + } |
616 | 652 | } |
0 commit comments