@@ -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,112 @@ 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 ' ] ?? [];
336
+ return $ list ;
337
+ }
356
338
357
- foreach ($ param ['schema ' ]['properties ' ] as $ paramName => $ value ) {
358
- if (!in_array ($ paramName , $ whitelistedParams )) {
359
- unset($ param ['schema ' ]['properties ' ][$ paramName ]);
360
- }
361
- }
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
+ if (isset ($ additionalMethod ['deprecated ' ])) {
353
+ $ duplicatedMethod ['deprecated ' ] = $ additionalMethod ['deprecated ' ];
354
+ $ duplicatedMethod ['x-appwrite ' ]['deprecated ' ] = $ additionalMethod ['deprecated ' ];
355
+ } else {
356
+ // remove inherited deprecations!
357
+ unset($ duplicatedMethod ['deprecated ' ]);
358
+ unset($ duplicatedMethod ['x-appwrite ' ]['deprecated ' ]);
359
+ }
362
360
363
- $ param ['schema ' ]['required ' ] = $ additionalMethod ['required ' ] ?? [];
364
- $ params [$ key ] = $ param ;
365
- }
366
- }
361
+ // Update Response
362
+ $ responses = $ additionalMethod ['responses ' ];
363
+ $ convertedResponse = [];
364
+
365
+ foreach ($ responses as $ desc ) {
366
+ $ code = $ desc ['code ' ];
367
+ if (isset ($ desc ['model ' ])) {
368
+ if (\is_array ($ desc ['model ' ])) {
369
+ $ convertedResponse [$ code ] = [
370
+ 'schema ' => [
371
+ 'x-oneOf ' => \array_map (fn ($ model ) => [
372
+ '$ref ' => $ model ,
373
+ ], $ desc ['model ' ]),
374
+ ],
375
+ ];
376
+ continue ;
377
+ }
367
378
368
- return ;
369
- };
379
+ $ convertedResponse [$ code ] = [
380
+ 'schema ' => [
381
+ '$ref ' => $ desc ['model ' ],
382
+ ],
383
+ ];
384
+ }
385
+ }
370
386
371
- $ handleParams ( $ duplicatedMethod ['parameters ' ]) ;
387
+ $ duplicatedMethod ['responses ' ] = $ convertedResponse ;
372
388
373
- // Overwrite description and name if method has one
374
- if (!empty ($ additionalMethod ['name ' ])) {
375
- $ duplicatedMethod ['summary ' ] = $ additionalMethod ['name ' ];
389
+ // Remove non-whitelisted parameters on body parameters, also set required.
390
+ $ handleParams = function (&$ params ) use ($ additionalMethod ) {
391
+ if (isset ($ additionalMethod ['parameters ' ])) {
392
+ foreach ($ params as $ key => $ param ) {
393
+ if (empty ($ param ['in ' ]) || $ param ['in ' ] !== 'body ' || empty ($ param ['schema ' ]['properties ' ])) {
394
+ continue ;
376
395
}
377
396
378
- if (!empty ($ additionalMethod ['description ' ])) {
379
- $ duplicatedMethod ['description ' ] = $ additionalMethod ['description ' ];
397
+ $ whitelistedParams = $ additionalMethod ['parameters ' ];
398
+
399
+ foreach ($ param ['schema ' ]['properties ' ] as $ paramName => $ value ) {
400
+ if (!in_array ($ paramName , $ whitelistedParams )) {
401
+ unset($ param ['schema ' ]['properties ' ][$ paramName ]);
402
+ }
380
403
}
381
404
382
- $ list [] = $ this ->parseMethod ($ methodName , $ pathName , $ duplicatedMethod );
405
+ $ param ['schema ' ]['required ' ] = $ additionalMethod ['required ' ] ?? [];
406
+ $ params [$ key ] = $ param ;
383
407
}
384
408
}
409
+ };
410
+
411
+ $ handleParams ($ duplicatedMethod ['parameters ' ]);
412
+
413
+ // Overwrite description and name if method has one
414
+ if (!empty ($ additionalMethod ['name ' ])) {
415
+ $ duplicatedMethod ['summary ' ] = $ additionalMethod ['name ' ];
385
416
}
386
417
387
- return $ list ;
418
+ if (!empty ($ additionalMethod ['description ' ])) {
419
+ $ duplicatedMethod ['description ' ] = $ additionalMethod ['description ' ];
420
+ }
421
+
422
+ return $ this ->parseMethod ($ methodName , $ pathName , $ duplicatedMethod );
423
+ }
424
+
425
+ /**
426
+ * @param array $method
427
+ * @param string $service
428
+ * @return string
429
+ */
430
+ public function getTargetNamespace (array $ method , string $ service ): string
431
+ {
432
+ return $ method ['namespace ' ] ?? $ service ;
388
433
}
389
434
390
435
/**
0 commit comments