@@ -302,7 +302,19 @@ public function getMethods($service)
302
302
303
303
foreach ($ paths as $ pathName => $ path ) {
304
304
foreach ($ path as $ methodName => $ method ) {
305
- if (!(isset ($ method ['tags ' ]) && is_array ($ method ['tags ' ]) && in_array ($ service , $ method ['tags ' ]))) {
305
+ $ isCurrentService = isset ($ method ['tags ' ]) && is_array ($ method ['tags ' ]) && in_array ($ service , $ method ['tags ' ]);
306
+
307
+ if (!$ isCurrentService ) {
308
+ if (!empty ($ method ['x-appwrite ' ]['methods ' ] ?? [])) {
309
+ foreach ($ method ['x-appwrite ' ]['methods ' ] as $ additionalMethod ) {
310
+ // has multiple namespaced methods!
311
+ $ targetNamespace = $ this ->getTargetNamespace ($ additionalMethod , $ service );
312
+
313
+ if ($ targetNamespace === $ service ) {
314
+ $ list [] = $ this ->handleAdditionalMethods ($ methodName , $ pathName , $ method , $ additionalMethod );
315
+ }
316
+ }
317
+ }
306
318
continue ;
307
319
}
308
320
@@ -312,79 +324,103 @@ public function getMethods($service)
312
324
}
313
325
314
326
foreach ($ method ['x-appwrite ' ]['methods ' ] as $ additionalMethod ) {
315
- $ duplicatedMethod = $ method ;
316
- $ duplicatedMethod ['x-appwrite ' ]['method ' ] = $ additionalMethod ['name ' ];
317
- $ duplicatedMethod ['x-appwrite ' ]['auth ' ] = $ additionalMethod ['auth ' ] ?? [];
318
-
319
- // Update Response
320
- $ responses = $ additionalMethod ['responses ' ];
321
- $ convertedResponse = [];
322
-
323
- foreach ($ responses as $ desc ) {
324
- $ code = $ desc ['code ' ];
325
- if (isset ($ desc ['model ' ])) {
326
- if (\is_array ($ desc ['model ' ])) {
327
- $ convertedResponse [$ code ] = [
328
- 'schema ' => [
329
- 'x-oneOf ' => \array_map (fn ($ model ) => [
330
- '$ref ' => $ model ,
331
- ], $ desc ['model ' ]),
332
- ],
333
- ];
334
- continue ;
335
- }
327
+ $ targetNamespace = $ this ->getTargetNamespace ($ additionalMethod , $ service );
336
328
337
- $ convertedResponse [$ code ] = [
338
- 'schema ' => [
339
- '$ref ' => $ desc ['model ' ],
340
- ],
341
- ];
342
- }
329
+ if ($ targetNamespace === $ service ) {
330
+ $ list [] = $ this ->handleAdditionalMethods ($ methodName , $ pathName , $ method , $ additionalMethod );
343
331
}
332
+ }
333
+ }
334
+ }
344
335
345
- $ duplicatedMethod ['responses ' ] = $ convertedResponse ;
346
-
347
- // Remove non-whitelisted parameters on body parameters, also set required.
348
- $ handleParams = function (&$ params ) use ($ additionalMethod ) {
349
- if (isset ($ additionalMethod ['parameters ' ])) {
350
- foreach ($ params as $ key => $ param ) {
351
- if (empty ($ param ['in ' ]) || $ param ['in ' ] !== 'body ' || empty ($ param ['schema ' ]['properties ' ])) {
352
- continue ;
353
- }
354
-
355
- $ whitelistedParams = $ additionalMethod ['parameters ' ] ?? [];
356
-
357
- foreach ($ param ['schema ' ]['properties ' ] as $ paramName => $ value ) {
358
- if (!in_array ($ paramName , $ whitelistedParams )) {
359
- unset($ param ['schema ' ]['properties ' ][$ paramName ]);
360
- }
361
- }
336
+ return $ list ;
337
+ }
362
338
363
- $ param ['schema ' ]['required ' ] = $ additionalMethod ['required ' ] ?? [];
364
- $ params [$ key ] = $ param ;
365
- }
366
- }
339
+ /**
340
+ * @param $methodName
341
+ * @param $pathName
342
+ * @param $method
343
+ * @param $additionalMethod
344
+ * @return array
345
+ */
346
+ private function handleAdditionalMethods ($ methodName , $ pathName , $ method , $ additionalMethod ): array
347
+ {
348
+ $ duplicatedMethod = $ method ;
349
+ $ duplicatedMethod ['x-appwrite ' ]['method ' ] = $ additionalMethod ['name ' ];
350
+ $ duplicatedMethod ['x-appwrite ' ]['auth ' ] = $ additionalMethod ['auth ' ] ?? [];
351
+
352
+ // Update Response
353
+ $ responses = $ additionalMethod ['responses ' ];
354
+ $ convertedResponse = [];
355
+
356
+ foreach ($ responses as $ desc ) {
357
+ $ code = $ desc ['code ' ];
358
+ if (isset ($ desc ['model ' ])) {
359
+ if (\is_array ($ desc ['model ' ])) {
360
+ $ convertedResponse [$ code ] = [
361
+ 'schema ' => [
362
+ 'x-oneOf ' => \array_map (fn ($ model ) => [
363
+ '$ref ' => $ model ,
364
+ ], $ desc ['model ' ]),
365
+ ],
366
+ ];
367
+ continue ;
368
+ }
367
369
368
- return ;
369
- };
370
+ $ convertedResponse [$ code ] = [
371
+ 'schema ' => [
372
+ '$ref ' => $ desc ['model ' ],
373
+ ],
374
+ ];
375
+ }
376
+ }
370
377
371
- $ handleParams ( $ duplicatedMethod ['parameters ' ]) ;
378
+ $ duplicatedMethod ['responses ' ] = $ convertedResponse ;
372
379
373
- // Overwrite description and name if method has one
374
- if (!empty ($ additionalMethod ['name ' ])) {
375
- $ duplicatedMethod ['summary ' ] = $ additionalMethod ['name ' ];
380
+ // Remove non-whitelisted parameters on body parameters, also set required.
381
+ $ handleParams = function (&$ params ) use ($ additionalMethod ) {
382
+ if (isset ($ additionalMethod ['parameters ' ])) {
383
+ foreach ($ params as $ key => $ param ) {
384
+ if (empty ($ param ['in ' ]) || $ param ['in ' ] !== 'body ' || empty ($ param ['schema ' ]['properties ' ])) {
385
+ continue ;
376
386
}
377
387
378
- if (!empty ($ additionalMethod ['description ' ])) {
379
- $ duplicatedMethod ['description ' ] = $ additionalMethod ['description ' ];
388
+ $ whitelistedParams = $ additionalMethod ['parameters ' ];
389
+
390
+ foreach ($ param ['schema ' ]['properties ' ] as $ paramName => $ value ) {
391
+ if (!in_array ($ paramName , $ whitelistedParams )) {
392
+ unset($ param ['schema ' ]['properties ' ][$ paramName ]);
393
+ }
380
394
}
381
395
382
- $ list [] = $ this ->parseMethod ($ methodName , $ pathName , $ duplicatedMethod );
396
+ $ param ['schema ' ]['required ' ] = $ additionalMethod ['required ' ] ?? [];
397
+ $ params [$ key ] = $ param ;
383
398
}
384
399
}
400
+ };
401
+
402
+ $ handleParams ($ duplicatedMethod ['parameters ' ]);
403
+
404
+ // Overwrite description and name if method has one
405
+ if (!empty ($ additionalMethod ['name ' ])) {
406
+ $ duplicatedMethod ['summary ' ] = $ additionalMethod ['name ' ];
385
407
}
386
408
387
- return $ list ;
409
+ if (!empty ($ additionalMethod ['description ' ])) {
410
+ $ duplicatedMethod ['description ' ] = $ additionalMethod ['description ' ];
411
+ }
412
+
413
+ return $ this ->parseMethod ($ methodName , $ pathName , $ duplicatedMethod );
414
+ }
415
+
416
+ /**
417
+ * @param array $method
418
+ * @param string $service
419
+ * @return string
420
+ */
421
+ public function getTargetNamespace (array $ method , string $ service ): string
422
+ {
423
+ return $ method ['namespace ' ] ?? $ service ;
388
424
}
389
425
390
426
/**
0 commit comments