forked from zircote/swagger-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRefTest.php
More file actions
62 lines (53 loc) · 1.77 KB
/
Copy pathRefTest.php
File metadata and controls
62 lines (53 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php declare(strict_types=1);
/**
* @license Apache 2.0
*/
namespace OpenApi\Tests;
use OpenApi\Analysis;
use OpenApi\Annotations as OA;
use OpenApi\Generator;
class RefTest extends OpenApiTestCase
{
public function testRef(): void
{
$openapi = $this->createOpenApiWithInfo();
$info = $openapi->ref('#/info');
$this->assertInstanceOf(OA\Info::class, $info);
$comment = <<<END
@OA\Post(
path="/api/~/endpoint",
@OA\Response(
response="default",
description="A response",
@OA\JsonContent(ref="#/components/schemas/String/x-custom-key")
)
)
@OA\Schema(
schema="String",
@OA\Property(property="value", type="string"),
x={
"custom-key": @OA\Schema(
@OA\Property(property="value", type="string"),
)
}
)
END;
$openapi->merge($this->annotationsFromDocBlockParser($comment));
$analysis = new Analysis([], $this->getContext());
$analysis->addAnnotation($openapi, $this->getContext());
(new Generator())->getProcessorPipeline()->process($analysis);
$analysis->validate();
// escape / as ~1
// escape ~ as ~0
$response = $openapi->ref('#/paths/~1api~1~0~1endpoint/post/responses/default');
$this->assertInstanceOf(OA\Response::class, $response);
$this->assertSame('A response', $response->description);
// ref x value
$schema = $openapi->ref('#/components/schemas/String/x-custom-key');
$this->assertInstanceOf(OA\Schema::class, $schema);
// ref x with deep
$property = $openapi->ref('#/components/schemas/String/x-custom-key/properties/value');
$this->assertInstanceOf(OA\Property::class, $property);
$this->assertSame('string', $property->type);
}
}