Skip to content

Commit 92b4527

Browse files
authored
test(openapi): add openapi test for normalization with attributes (#7772)
1 parent a2efb39 commit 92b4527

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/Functional/OpenApiTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
namespace ApiPlatform\Tests\Functional;
1515

1616
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
17+
use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\ChildAttribute;
1718
use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Crud;
1819
use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\CrudOpenApiApiPlatformTag;
1920
use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\DummyWebhook;
2021
use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue6151\OverrideOpenApiResponses;
22+
use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\ParentAttribute;
2123
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\AbstractDummy;
2224
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\CircularReference;
2325
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\CompositeItem;
@@ -100,6 +102,8 @@ public static function getResources(): array
100102
JsonSchemaResource::class,
101103
JsonSchemaResourceRelated::class,
102104
WrappedResponseEntity::class,
105+
ParentAttribute::class,
106+
ChildAttribute::class,
103107
];
104108
}
105109

@@ -613,4 +617,36 @@ public function testRetrieveTheEntrypointWithUrlFormat(): void
613617
$this->assertResponseHeaderSame('content-type', 'application/vnd.openapi+json; charset=utf-8');
614618
$this->assertJson($response->getContent());
615619
}
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+
}
616652
}

0 commit comments

Comments
 (0)