NestedPropertyTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php declare(strict_types=1);
  2. /**
  3. * @license Apache 2.0
  4. */
  5. namespace OpenApiTests;
  6. use OpenApi\Processors\AugmentProperties;
  7. use OpenApi\Processors\AugmentSchemas;
  8. use OpenApi\Processors\MergeIntoComponents;
  9. use OpenApi\Processors\MergeIntoOpenApi;
  10. use OpenApi\StaticAnalyser;
  11. use const OpenApi\UNDEFINED;
  12. class NestedPropertyTest extends OpenApiTestCase
  13. {
  14. public function testNestedProperties()
  15. {
  16. $analyser = new StaticAnalyser();
  17. $analysis = $analyser->fromFile(__DIR__.'/Fixtures/NestedProperty.php');
  18. $analysis->process(new MergeIntoOpenApi());
  19. $analysis->process(new MergeIntoComponents());
  20. $analysis->process(new AugmentSchemas());
  21. $analysis->process(new AugmentProperties());
  22. $this->assertCount(1, $analysis->openapi->components->schemas);
  23. $schema = $analysis->openapi->components->schemas[0];
  24. $this->assertEquals('NestedProperty', $schema->schema);
  25. $this->assertCount(1, $schema->properties);
  26. $parentProperty = $schema->properties[0];
  27. $this->assertEquals('parentProperty', $parentProperty->property);
  28. $this->assertCount(1, $parentProperty->properties);
  29. $babyProperty = $parentProperty->properties[0];
  30. $this->assertEquals('babyProperty', $babyProperty->property);
  31. $this->assertCount(1, $babyProperty->properties);
  32. $theBabyOfBaby = $babyProperty->properties[0];
  33. $this->assertEquals('theBabyOfBaby', $theBabyOfBaby->property);
  34. $this->assertCount(1, $theBabyOfBaby->properties);
  35. // verbose not-recommend notations
  36. $theBabyOfBabyBaby = $theBabyOfBaby->properties[0];
  37. $this->assertEquals('theBabyOfBabyBaby', $theBabyOfBabyBaby->property);
  38. $this->assertSame(UNDEFINED, $theBabyOfBabyBaby->properties);
  39. }
  40. }