66
77class Swagger2 extends Spec
88{
9+ /**
10+ * @var array
11+ */
12+ private array $ serviceParams = [];
913
1014 /**
1115 * @return string
@@ -104,9 +108,11 @@ public function getServices()
104108 if (isset ($ method ['tags ' ])) {
105109 foreach ($ method ['tags ' ] as $ tag ) {
106110 if (!array_key_exists ($ tag , $ list )) {
111+ $ methods = $ this ->getMethods ($ tag );
107112 $ list [$ tag ] = [
108113 'name ' => $ tag ,
109- 'methods ' => $ this ->getMethods ($ tag ),
114+ 'methods ' => $ methods ,
115+ 'globalParams ' => $ this ->serviceParams [$ tag ] ?? [],
110116 ];
111117 }
112118 }
@@ -132,7 +138,7 @@ public function getServices()
132138 public function getMethods ($ service )
133139 {
134140 $ list = [];
135-
141+ $ serviceParams = [];
136142 $ security = $ this ->getAttribute ('securityDefinitions ' , []);
137143 $ paths = $ this ->getAttribute ('paths ' , []);
138144
@@ -204,6 +210,7 @@ public function getMethods($service)
204210 'default ' => $ parameter ['default ' ] ?? null ,
205211 'example ' => $ parameter ['x-example ' ] ?? null ,
206212 'isUploadID ' => $ parameter ['x-upload-id ' ] ?? false ,
213+ 'isGlobal ' => $ parameter ['x-global ' ] ?? false ,
207214 'array ' => [
208215 'type ' => $ parameter ['items ' ]['type ' ] ?? '' ,
209216 ],
@@ -215,6 +222,10 @@ public function getMethods($service)
215222
216223 $ param ['default ' ] = (is_array ($ param ['default ' ])) ? json_encode ($ param ['default ' ]) : $ param ['default ' ];
217224
225+ if (($ parameter ['x-global ' ] ?? false )) {
226+ $ serviceParams [$ param ['name ' ]] = $ param ;
227+ }
228+
218229 switch ($ parameter ['in ' ]) {
219230 case 'header ' :
220231 $ output ['parameters ' ]['header ' ][] = $ param ;
@@ -239,6 +250,7 @@ public function getMethods($service)
239250 $ param ['required ' ] = (in_array ($ key , $ bodyRequired ));
240251 $ param ['default ' ] = $ value ['default ' ] ?? null ;
241252 $ param ['example ' ] = $ value ['x-example ' ] ?? null ;
253+ $ param ['isGlobal ' ] = $ value ['x-global ' ] ?? false ;
242254 $ param ['isUploadID ' ] = $ value ['x-upload-id ' ] ?? false ;
243255 $ param ['array ' ] = [
244256 'type ' => $ value ['items ' ]['type ' ] ?? '' ,
@@ -270,6 +282,8 @@ public function getMethods($service)
270282 }
271283 }
272284
285+ $ this ->serviceParams [$ service ] = $ serviceParams ;
286+
273287 return $ list ;
274288 }
275289
0 commit comments