88namespace cebe \openapi \spec ;
99
1010use cebe \openapi \DocumentContextInterface ;
11- use cebe \openapi \exceptions \IOException ;
1211use cebe \openapi \exceptions \TypeErrorException ;
1312use cebe \openapi \exceptions \UnresolvableReferenceException ;
1413use cebe \openapi \json \InvalidJsonPointerSyntaxException ;
1716use cebe \openapi \json \NonexistentJsonPointerReferenceException ;
1817use cebe \openapi \ReferenceContext ;
1918use cebe \openapi \SpecObjectInterface ;
20- use Symfony \Component \Yaml \Yaml ;
2119
2220/**
2321 * Reference Object
@@ -37,6 +35,14 @@ class Reference implements SpecObjectInterface, DocumentContextInterface
3735 * @var string
3836 */
3937 private $ _ref ;
38+ /**
39+ * @var string|null
40+ */
41+ private $ _summary ;
42+ /**
43+ * @var string|null
44+ */
45+ private $ _description ;
4046 /**
4147 * @var JsonReference|null
4248 */
@@ -81,15 +87,33 @@ public function __construct(array $data, ?string $to = null)
8187 'Unable to instantiate Reference Object, value of $ref must be a string. '
8288 );
8389 }
90+ if (isset ($ data ['summary ' ]) && !is_string ($ data ['summary ' ])) {
91+ throw new TypeErrorException (
92+ 'Unable to instantiate Reference Object, value of summary must be a string. '
93+ );
94+ }
95+ if (isset ($ data ['description ' ]) && !is_string ($ data ['description ' ])) {
96+ throw new TypeErrorException (
97+ 'Unable to instantiate Reference Object, value of description must be a string. '
98+ );
99+ }
100+
84101 $ this ->_to = $ to ;
85102 $ this ->_ref = $ data ['$ref ' ];
103+ $ this ->_summary = $ data ['summary ' ] ?? null ;
104+ $ this ->_description = $ data ['description ' ] ?? null ;
86105 try {
87- $ this ->_jsonReference = JsonReference::createFromReference ($ this ->_ref );
106+ $ this ->_jsonReference = JsonReference::createFromReference (
107+ $ this ->_ref ,
108+ $ this ->_summary ,
109+ $ this ->_description
110+ );
88111 } catch (InvalidJsonPointerSyntaxException $ e ) {
89112 $ this ->_errors [] = 'Reference: value of $ref is not a valid JSON pointer: ' . $ e ->getMessage ();
90113 }
91- if (count ($ data ) !== 1 ) {
92- $ this ->_errors [] = 'Reference: additional properties are given. Only $ref should be set in a Reference Object. ' ;
114+
115+ if (!empty (array_diff (array_keys ($ data ), ['$ref ' , 'summary ' , 'description ' ]))) {
116+ $ this ->_errors [] = 'Reference: additional properties are given. Only $ref, summary and description should be set in a Reference Object. ' ;
93117 }
94118 }
95119
@@ -99,7 +123,11 @@ public function __construct(array $data, ?string $to = null)
99123 */
100124 public function getSerializableData ()
101125 {
102- return (object ) ['$ref ' => $ this ->_ref ];
126+ return (object ) array_filter ([
127+ '$ref ' => $ this ->_ref ,
128+ 'summary ' => $ this ->_summary ,
129+ 'description ' => $ this ->_description ,
130+ ]);
103131 }
104132
105133 /**
@@ -135,6 +163,16 @@ public function getReference()
135163 return $ this ->_ref ;
136164 }
137165
166+ public function getSummary ()
167+ {
168+ return $ this ->_summary ;
169+ }
170+
171+ public function getDescription ()
172+ {
173+ return $ this ->_description ;
174+ }
175+
138176 /**
139177 * @return JsonReference the JSON Reference.
140178 */
0 commit comments