3
3
use cebe \openapi \Reader ;
4
4
use cebe \openapi \spec \OpenApi ;
5
5
use cebe \openapi \spec \Reference ;
6
+ use cebe \openapi \spec \Response ;
6
7
use cebe \openapi \spec \Schema ;
7
8
use cebe \openapi \spec \Example ;
8
9
@@ -29,6 +30,9 @@ public function testResolveInDocument()
29
30
examples:
30
31
frog-example:
31
32
description: a frog
33
+ responses:
34
+ Pet:
35
+ description: returns a pet
32
36
paths:
33
37
'/pet':
34
38
get:
@@ -42,25 +46,33 @@ public function testResolveInDocument()
42
46
examples:
43
47
frog:
44
48
$ref: "#/components/examples/frog-example"
49
+ '/pet/1':
50
+ get:
51
+ responses:
52
+ 200:
53
+ $ref: "#/components/responses/Pet"
45
54
YAML
46
55
, OpenApi::class);
47
56
48
57
$ result = $ openapi ->validate ();
49
58
$ this ->assertEquals ([], $ openapi ->getErrors ());
50
59
$ this ->assertTrue ($ result );
51
60
52
- /** @var $response \cebe\openapi\spec\Response */
53
- $ response = $ openapi ->paths ->getPath ('/pet ' )->get ->responses ['200 ' ];
54
- $ this ->assertInstanceOf (Reference::class, $ response ->content ['application/json ' ]->schema );
55
- $ this ->assertInstanceOf (Reference::class, $ response ->content ['application/json ' ]->examples ['frog ' ]);
61
+ /** @var $petResponse Response */
62
+ $ petResponse = $ openapi ->paths ->getPath ('/pet ' )->get ->responses ['200 ' ];
63
+ $ this ->assertInstanceOf (Reference::class, $ petResponse ->content ['application/json ' ]->schema );
64
+ $ this ->assertInstanceOf (Reference::class, $ petResponse ->content ['application/json ' ]->examples ['frog ' ]);
65
+ $ this ->assertInstanceOf (Reference::class, $ openapi ->paths ->getPath ('/pet/1 ' )->get ->responses ['200 ' ]);
56
66
57
67
$ openapi ->resolveReferences (new \cebe \openapi \ReferenceContext ($ openapi , 'file:///tmp/openapi.yaml ' ));
58
68
59
- $ this ->assertInstanceOf (Schema::class, $ refSchema = $ response ->content ['application/json ' ]->schema );
60
- $ this ->assertInstanceOf (Example::class, $ refExample = $ response ->content ['application/json ' ]->examples ['frog ' ]);
69
+ $ this ->assertInstanceOf (Schema::class, $ refSchema = $ petResponse ->content ['application/json ' ]->schema );
70
+ $ this ->assertInstanceOf (Example::class, $ refExample = $ petResponse ->content ['application/json ' ]->examples ['frog ' ]);
71
+ $ this ->assertInstanceOf (Response::class, $ refResponse = $ openapi ->paths ->getPath ('/pet/1 ' )->get ->responses ['200 ' ]);
61
72
62
73
$ this ->assertSame ($ openapi ->components ->schemas ['Pet ' ], $ refSchema );
63
74
$ this ->assertSame ($ openapi ->components ->examples ['frog-example ' ], $ refExample );
75
+ $ this ->assertSame ($ openapi ->components ->responses ['Pet ' ], $ refResponse );
64
76
}
65
77
66
78
public function testResolveCyclicReferenceInDocument ()
@@ -105,7 +117,7 @@ public function testResolveCyclicReferenceInDocument()
105
117
$ this ->assertEquals ([], $ openapi ->getErrors ());
106
118
$ this ->assertTrue ($ result );
107
119
108
- /** @var $response \cebe\openapi\spec\ Response */
120
+ /** @var $response Response */
109
121
$ response = $ openapi ->paths ->getPath ('/pet ' )->get ->responses ['200 ' ];
110
122
$ this ->assertInstanceOf (Reference::class, $ response ->content ['application/json ' ]->schema );
111
123
$ this ->assertInstanceOf (Reference::class, $ response ->content ['application/json ' ]->examples ['frog ' ]);
0 commit comments