@@ -37,6 +37,39 @@ public function __construct(OpenApi $openApi)
37
37
$ this ->openApi = $ openApi ;
38
38
}
39
39
40
+ /**
41
+ * @return Parameter[]
42
+ *
43
+ * @throws NoPath
44
+ */
45
+ public function findOperationAndPathLevelSpecs (OperationAddress $ addr ) : array
46
+ {
47
+ $ spec = $ this ->findOperationSpec ($ addr );
48
+
49
+ // 1. Collect operation-level params
50
+ $ pathSpecs = [];
51
+
52
+ foreach ($ spec ->parameters as $ p ) {
53
+ if ($ p ->in !== 'path ' ) {
54
+ continue ;
55
+ }
56
+
57
+ $ pathSpecs [$ p ->name ] = $ p ;
58
+ }
59
+
60
+ // 2. Collect path-level params
61
+ $ pathSpec = $ this ->findPathSpec ($ addr );
62
+ foreach ($ pathSpec ->parameters as $ p ) {
63
+ if ($ p ->in !== 'path ' ) {
64
+ continue ;
65
+ }
66
+
67
+ $ pathSpecs += [$ p ->name => $ p ]; // union won't override
68
+ }
69
+
70
+ return $ pathSpecs ;
71
+ }
72
+
40
73
/**
41
74
* Find a particular operation (path + method) in the spec
42
75
*
@@ -65,46 +98,14 @@ public function findOperationSpec(OperationAddress $addr) : Operation
65
98
*/
66
99
public function findPathSpec (OperationAddress $ addr ) : PathItem
67
100
{
68
- $ pathSpec = $ this ->openApi ->paths ->getPath ($ addr ->path ());
101
+ $ finder = new PathFinder ($ this ->openApi , $ addr ->path (), $ addr ->method ());
102
+ $ pathSpecs = $ finder ->getPathMatches ();
69
103
70
- if (! $ pathSpec ) {
104
+ if (empty ( $ pathSpecs ) === true ) {
71
105
throw NoPath::fromPath ($ addr ->path ());
72
106
}
73
107
74
- return $ pathSpec ;
75
- }
76
-
77
- /**
78
- * @return Parameter[]
79
- *
80
- * @throws NoPath
81
- */
82
- public function findPathSpecs (OperationAddress $ addr ) : array
83
- {
84
- $ spec = $ this ->findOperationSpec ($ addr );
85
-
86
- // 1. Collect operation-level params
87
- $ pathSpecs = [];
88
-
89
- foreach ($ spec ->parameters as $ p ) {
90
- if ($ p ->in !== 'path ' ) {
91
- continue ;
92
- }
93
-
94
- $ pathSpecs [$ p ->name ] = $ p ;
95
- }
96
-
97
- // 2. Collect path-level params
98
- $ pathSpec = $ this ->findPathSpec ($ addr );
99
- foreach ($ pathSpec ->parameters as $ p ) {
100
- if ($ p ->in !== 'path ' ) {
101
- continue ;
102
- }
103
-
104
- $ pathSpecs += [$ p ->name => $ p ]; // union won't override
105
- }
106
-
107
- return $ pathSpecs ;
108
+ return $ pathSpecs [0 ];
108
109
}
109
110
110
111
/**
@@ -198,10 +199,13 @@ public function findBodySpec(OperationAddress $addr) : array
198
199
*/
199
200
public function findResponseSpec ($ addr ) : ResponseSpec
200
201
{
201
- Assert::isInstanceOfAny ($ addr , [
202
- ResponseAddress::class,
203
- CallbackResponseAddress::class,
204
- ]);
202
+ Assert::isInstanceOfAny (
203
+ $ addr ,
204
+ [
205
+ ResponseAddress::class,
206
+ CallbackResponseAddress::class,
207
+ ]
208
+ );
205
209
206
210
$ operation = $ this ->findOperationSpec ($ addr );
207
211
@@ -237,7 +241,8 @@ public function findHeaderSpecs(OperationAddress $addr) : array
237
241
$ spec = $ this ->findOperationSpec ($ addr );
238
242
239
243
// 1. Collect operation level headers from "parameters" keyword
240
- // An API call may require that custom headers be sent with an HTTP request. OpenAPI lets you define custom request headers as in: header parameters.
244
+ // An API call may require that custom headers be sent with an HTTP request. OpenAPI lets you define custom
245
+ // request headers as in: header parameters.
241
246
$ headerSpecs = [];
242
247
foreach ($ spec ->parameters as $ p ) {
243
248
if ($ p ->in !== 'header ' ) {
@@ -307,13 +312,23 @@ private function findCallbackInOperation(CallbackAddress $addr, Operation $opera
307
312
{
308
313
$ callbacks = $ operation ->callbacks ;
309
314
if (! isset ($ callbacks [$ addr ->callbackName ()])) {
310
- throw NoCallback::fromCallbackPath ($ addr ->path (), $ addr ->method (), $ addr ->callbackName (), $ addr ->callbackMethod ());
315
+ throw NoCallback::fromCallbackPath (
316
+ $ addr ->path (),
317
+ $ addr ->method (),
318
+ $ addr ->callbackName (),
319
+ $ addr ->callbackMethod ()
320
+ );
311
321
}
312
322
313
323
/** @var Callback $callback */
314
324
$ callback = $ callbacks [$ addr ->callbackName ()];
315
325
if (! isset ($ callback ->getRequest ()->getOperations ()[$ addr ->callbackMethod ()])) {
316
- throw NoCallback::fromCallbackPath ($ addr ->path (), $ addr ->method (), $ addr ->callbackName (), $ addr ->callbackMethod ());
326
+ throw NoCallback::fromCallbackPath (
327
+ $ addr ->path (),
328
+ $ addr ->method (),
329
+ $ addr ->callbackName (),
330
+ $ addr ->callbackMethod ()
331
+ );
317
332
}
318
333
319
334
return $ callback ->getRequest ()->getOperations ()[$ addr ->callbackMethod ()];
0 commit comments