4
0

RefTest.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php declare(strict_types=1);
  2. /**
  3. * @license Apache 2.0
  4. */
  5. namespace OpenApiTests;
  6. use OpenApi\Analysis;
  7. use OpenApi\Annotations\Info;
  8. use OpenApi\Annotations\Response;
  9. use OpenApi\Context;
  10. class RefTest extends OpenApiTestCase
  11. {
  12. public function testRef()
  13. {
  14. $openapi = $this->createOpenApiWithInfo();
  15. $info = $openapi->ref('#/info');
  16. $this->assertInstanceOf(Info::class, $info);
  17. $comment = <<<END
  18. @OA\Get(
  19. path="/api/~/endpoint",
  20. @OA\Response(response="default", description="A response")
  21. )
  22. END;
  23. $openapi->merge($this->parseComment($comment));
  24. $analysis = new Analysis();
  25. $analysis->addAnnotation($openapi, Context::detect());
  26. $analysis->process();
  27. $analysis->validate();
  28. // escape / as ~1
  29. // escape ~ as ~0
  30. $response = $openapi->ref('#/paths/~1api~1~0~1endpoint/get/responses/default');
  31. $this->assertInstanceOf(Response::class, $response);
  32. $this->assertSame('A response', $response->description);
  33. }
  34. }