@@ -36,6 +36,47 @@ public function testReadYaml()
36
36
$ this ->assertApiContent ($ openapi );
37
37
}
38
38
39
+ /**
40
+ * Test if reading YAML file with anchors works
41
+ */
42
+ public function testReadYamlWithAnchors ()
43
+ {
44
+ $ openApiFile = __DIR__ . '/spec/data/traits-mixins.yaml ' ;
45
+ $ openapi = \cebe \openapi \Reader::readFromYamlFile ($ openApiFile );
46
+
47
+ $ this ->assertApiContent ($ openapi );
48
+
49
+ $ putOperation = $ openapi ->paths ['/foo ' ]->put ;
50
+ $ this ->assertEquals ('create foo ' , $ putOperation ->description );
51
+ $ this ->assertTrue ($ putOperation ->responses ->hasResponse ('200 ' ));
52
+ $ this ->assertTrue ($ putOperation ->responses ->hasResponse ('404 ' ));
53
+ $ this ->assertTrue ($ putOperation ->responses ->hasResponse ('428 ' ));
54
+ $ this ->assertTrue ($ putOperation ->responses ->hasResponse ('default ' ));
55
+
56
+ $ respOk = $ putOperation ->responses ->getResponse ('200 ' );
57
+ $ this ->assertEquals ('request succeeded ' , $ respOk ->description );
58
+ $ this ->assertEquals ('the request id ' , $ respOk ->headers ['X-Request-Id ' ]->description );
59
+
60
+ $ resp404 = $ putOperation ->responses ->getResponse ('404 ' );
61
+ $ this ->assertEquals ('resource not found ' , $ resp404 ->description );
62
+ $ this ->assertEquals ('the request id ' , $ resp404 ->headers ['X-Request-Id ' ]->description );
63
+
64
+ $ resp428 = $ putOperation ->responses ->getResponse ('428 ' );
65
+ $ this ->assertEquals ('resource not found ' , $ resp428 ->description );
66
+ $ this ->assertEquals ('the request id ' , $ resp428 ->headers ['X-Request-Id ' ]->description );
67
+
68
+ $ respDefault = $ putOperation ->responses ->getResponse ('default ' );
69
+ $ this ->assertEquals ('resource not found ' , $ respDefault ->description );
70
+ $ this ->assertEquals ('the request id ' , $ respDefault ->headers ['X-Request-Id ' ]->description );
71
+
72
+ $ foo = $ openapi ->components ->schemas ['Foo ' ];
73
+ $ this ->assertArrayHasKey ('uuid ' , $ foo ->properties );
74
+ $ this ->assertArrayHasKey ('name ' , $ foo ->properties );
75
+ $ this ->assertArrayHasKey ('id ' , $ foo ->properties );
76
+ $ this ->assertArrayHasKey ('description ' , $ foo ->properties );
77
+ $ this ->assertEquals ('uuid of the resource ' , $ foo ->properties ['uuid ' ]->description );
78
+ }
79
+
39
80
private function assertApiContent (\cebe \openapi \spec \OpenApi $ openapi )
40
81
{
41
82
$ result = $ openapi ->validate ();
0 commit comments