@@ -125,7 +125,7 @@ public function getServices()
125
125
return $ list ;
126
126
}
127
127
128
- protected function convertMethod (string $ methodName , string $ pathName , array $ method ): array
128
+ protected function parseMethod (string $ methodName , string $ pathName , array $ method ): array
129
129
{
130
130
$ security = $ this ->getAttribute ('securityDefinitions ' , []);
131
131
$ methodAuth = $ method ['x-appwrite ' ]['auth ' ] ?? [];
@@ -286,76 +286,78 @@ public function getMethods($service)
286
286
287
287
foreach ($ paths as $ pathName => $ path ) {
288
288
foreach ($ path as $ methodName => $ method ) {
289
- if (isset ($ method ['tags ' ]) && is_array ($ method ['tags ' ]) && in_array ($ service , $ method ['tags ' ])) {
290
- // Handle method multiplexing
291
- if (!empty ($ method ['x-appwrite ' ]['multiplex ' ] ?? [])) {
292
- foreach ($ method ['x-appwrite ' ]['multiplex ' ] as $ multiplex ) {
293
- $ multiplexMethod = $ method ;
294
- $ multiplexMethod ['x-appwrite ' ]['method ' ] = $ multiplex ['name ' ];
295
-
296
- // Update Response
297
- $ responses = $ multiplexMethod ['responses ' ];
298
- $ convertedResponse = [];
299
-
300
- foreach ($ responses as $ code => $ desc ) {
301
- if (!isset ($ desc ['schema ' ]) || !isset ($ desc ['schema ' ]['x-oneOf ' ])) {
302
- continue ;
303
- }
289
+ if (!(isset ($ method ['tags ' ]) && is_array ($ method ['tags ' ]) && in_array ($ service , $ method ['tags ' ]))) {
290
+ continue ;
291
+ }
304
292
305
- foreach ( $ desc [ ' schema ' ]['x-oneOf ' ] as $ oneOf ) {
306
- if (! isset ( $ oneOf [ ' $ref ' ]) || ! str_ends_with ( $ oneOf [ ' $ref ' ] , $ multiplex [ ' response ' ])) {
307
- continue ;
308
- }
293
+ if ( empty ( $ method [ ' x-appwrite ' ]['multiplex ' ] ?? []) ) {
294
+ $ list [] = $ this -> parseMethod ( $ methodName , $ pathName , $ method );
295
+ continue ;
296
+ }
309
297
310
- $ convertedResponse [$ code ] = [
311
- 'description ' => $ desc ['description ' ],
312
- 'schema ' => $ oneOf ,
313
- ];
314
- }
298
+ foreach ($ method ['x-appwrite ' ]['multiplex ' ] as $ multiplex ) {
299
+ $ multiplexMethod = $ method ;
300
+ $ multiplexMethod ['x-appwrite ' ]['method ' ] = $ multiplex ['name ' ];
301
+
302
+ // Update Response
303
+ $ responses = $ multiplexMethod ['responses ' ];
304
+ $ convertedResponse = [];
305
+
306
+ foreach ($ responses as $ code => $ desc ) {
307
+ if (!isset ($ desc ['schema ' ]) || !isset ($ desc ['schema ' ]['x-oneOf ' ])) {
308
+ continue ;
309
+ }
310
+
311
+ foreach ($ desc ['schema ' ]['x-oneOf ' ] as $ oneOf ) {
312
+ if (!isset ($ oneOf ['$ref ' ]) || !str_ends_with ($ oneOf ['$ref ' ], $ multiplex ['response ' ])) {
313
+ continue ;
315
314
}
316
315
317
- $ multiplexMethod ['responses ' ] = $ convertedResponse ;
316
+ $ convertedResponse [$ code ] = [
317
+ 'description ' => $ desc ['description ' ],
318
+ 'schema ' => $ oneOf ,
319
+ ];
320
+ }
321
+ }
318
322
319
- // Remove non-whitelisted parameters on body parameters, also set required.
320
- $ handleParams = function (&$ params ) use ($ multiplex ) {
321
- if (isset ($ multiplex ['parameters ' ])) {
322
- foreach ($ params as $ key => $ param ) {
323
- if (empty ($ param ['in ' ]) || $ param ['in ' ] !== 'body ' || empty ($ param ['schema ' ]['properties ' ])) {
324
- continue ;
325
- }
323
+ $ multiplexMethod ['responses ' ] = $ convertedResponse ;
326
324
327
- $ whitelistedParams = $ multiplex ['parameters ' ] ?? [];
325
+ // Remove non-whitelisted parameters on body parameters, also set required.
326
+ $ handleParams = function (&$ params ) use ($ multiplex ) {
327
+ if (isset ($ multiplex ['parameters ' ])) {
328
+ foreach ($ params as $ key => $ param ) {
329
+ if (empty ($ param ['in ' ]) || $ param ['in ' ] !== 'body ' || empty ($ param ['schema ' ]['properties ' ])) {
330
+ continue ;
331
+ }
328
332
329
- foreach ($ param ['schema ' ]['properties ' ] as $ paramName => $ value ) {
330
- if (!in_array ($ paramName , $ whitelistedParams )) {
331
- unset($ param ['schema ' ]['properties ' ][$ paramName ]);
332
- }
333
- }
333
+ $ whitelistedParams = $ multiplex ['parameters ' ] ?? [];
334
334
335
- $ param ['schema ' ]['required ' ] = $ multiplex ['required ' ] ?? [];
336
- $ params [$ key ] = $ param ;
335
+ foreach ($ param ['schema ' ]['properties ' ] as $ paramName => $ value ) {
336
+ if (!in_array ($ paramName , $ whitelistedParams )) {
337
+ unset($ param ['schema ' ]['properties ' ][$ paramName ]);
337
338
}
338
339
}
339
340
340
- return ;
341
- };
341
+ $ param ['schema ' ]['required ' ] = $ multiplex ['required ' ] ?? [];
342
+ $ params [$ key ] = $ param ;
343
+ }
344
+ }
342
345
343
- $ handleParams ($ multiplexMethod ['parameters ' ]);
346
+ return ;
347
+ };
344
348
345
- // Overwrite description and name if multiplex has one
346
- if (!empty ($ multiplex ['name ' ])) {
347
- $ multiplexMethod ['summary ' ] = $ multiplex ['name ' ];
348
- }
349
+ $ handleParams ($ multiplexMethod ['parameters ' ]);
349
350
350
- if (!empty ($ multiplex ['description ' ])) {
351
- $ multiplexMethod ['description ' ] = $ multiplex ['description ' ];
352
- }
351
+ // Overwrite description and name if multiplex has one
352
+ if (!empty ($ multiplex ['name ' ])) {
353
+ $ multiplexMethod ['summary ' ] = $ multiplex ['name ' ];
354
+ }
353
355
354
- $ list [] = $ this ->convertMethod ($ methodName , $ pathName , $ multiplexMethod );
355
- }
356
- continue ;
356
+ if (!empty ($ multiplex ['description ' ])) {
357
+ $ multiplexMethod ['description ' ] = $ multiplex ['description ' ];
357
358
}
358
- $ list [] = $ this ->convertMethod ($ methodName , $ pathName , $ method );
359
+
360
+ $ list [] = $ this ->parseMethod ($ methodName , $ pathName , $ multiplexMethod );
359
361
}
360
362
}
361
363
}
0 commit comments