4
0

ItemsTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php declare(strict_types=1);
  2. /**
  3. * @license Apache 2.0
  4. */
  5. namespace OpenApiTests;
  6. use OpenApi\StaticAnalyser;
  7. class ItemsTest extends OpenApiTestCase
  8. {
  9. public function testItemTypeArray()
  10. {
  11. $annotations = $this->parseComment('@OA\Items(type="array")');
  12. $this->assertOpenApiLogEntryStartsWith('@OA\Items() is required when @OA\Items() has type "array" in ');
  13. $annotations[0]->validate();
  14. }
  15. public function testSchemaTypeArray()
  16. {
  17. $annotations = $this->parseComment('@OA\Schema(type="array")');
  18. $this->assertOpenApiLogEntryStartsWith('@OA\Items() is required when @OA\Schema() has type "array" in ');
  19. $annotations[0]->validate();
  20. }
  21. public function testTypeObject()
  22. {
  23. $this->countExceptions = 1;
  24. $notAllowedInQuery = $this->parseComment('@OA\Parameter(name="param",in="query",@OA\Schema(type="array",@OA\Items(type="object")))');
  25. $this->assertOpenApiLogEntryStartsWith('@OA\Items()->type="object" not allowed inside a @OA\Parameter() must be "string", "number", "integer", "boolean", "array" in ');
  26. $notAllowedInQuery[0]->validate();
  27. }
  28. public function testRefDefinitionInProperty()
  29. {
  30. $analyser = new StaticAnalyser();
  31. $analysis = $analyser->fromFile(__DIR__.'/Fixtures/UsingVar.php');
  32. $analysis->process();
  33. $this->assertCount(2, $analysis->openapi->components->schemas);
  34. $this->assertEquals('UsingVar', $analysis->openapi->components->schemas[0]->schema);
  35. $this->assertIsArray($analysis->openapi->components->schemas[0]->properties);
  36. $this->assertCount(2, $analysis->openapi->components->schemas[0]->properties);
  37. $this->assertEquals('name', $analysis->openapi->components->schemas[0]->properties[0]->property);
  38. $this->assertEquals('createdAt', $analysis->openapi->components->schemas[0]->properties[1]->property);
  39. $this->assertEquals('#/components/schemas/date', $analysis->openapi->components->schemas[0]->properties[1]->ref);
  40. }
  41. }