Skip to content

fix: implement service filtering based on exclusion rules #1090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 55 additions & 3 deletions src/SDK/SDK.php
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,58 @@ public function getParams(): array
return $this->params;
}

/**
* Get services filtered by exclusion rules
*
* @return array
*/
protected function getFilteredServices(): array
{
$allServices = $this->spec->getServices();
$filteredServices = [];

// Extract exclusion rules for services
$excludeServices = [];
$excludeFeatures = [];
foreach ($this->excludeRules['services'] ?? [] as $service) {
if (isset($service['name'])) {
$excludeServices[] = $service['name'];
}
if (isset($service['feature'])) {
$excludeFeatures[] = $service['feature'];
}
}

foreach ($allServices as $serviceName => $service) {
// Check if service is excluded by name
if (in_array($serviceName, $excludeServices)) {
continue;
}

// Check if service is excluded by feature
$methods = $this->spec->getMethods($serviceName);
$serviceFeatures = [
'upload' => $this->hasUploads($methods),
'location' => $this->hasLocation($methods),
'webAuth' => $this->hasWebAuth($methods),
];

$shouldExclude = false;
foreach ($excludeFeatures as $feature) {
if ($serviceFeatures[$feature] ?? false) {
$shouldExclude = true;
break;
}
}

if (!$shouldExclude) {
$filteredServices[$serviceName] = $service;
}
}

return $filteredServices;
}

/**
* @param string $target
* @throws Throwable
Expand All @@ -561,7 +613,7 @@ public function generate(string $target): void
'contactName' => $this->spec->getContactName(),
'contactURL' => $this->spec->getContactURL(),
'contactEmail' => $this->spec->getContactEmail(),
'services' => $this->spec->getServices(),
'services' => $this->getFilteredServices(),
'enums' => $this->spec->getEnums(),
'definitions' => $this->spec->getDefinitions(),
'global' => [
Expand Down Expand Up @@ -595,7 +647,7 @@ public function generate(string $target): void
copy(realpath(__DIR__ . '/../../templates/' . $file['template']), $destination);
break;
case 'service':
foreach ($this->spec->getServices() as $key => $service) {
foreach ($this->getFilteredServices() as $key => $service) {
$methods = $this->spec->getMethods($key);
$params['service'] = [
'globalParams' => $service['globalParams'] ?? [],
Expand Down Expand Up @@ -628,7 +680,7 @@ public function generate(string $target): void
}
break;
case 'method':
foreach ($this->spec->getServices() as $key => $service) {
foreach ($this->getFilteredServices() as $key => $service) {
$methods = $this->spec->getMethods($key);
$params['service'] = [
'name' => $key,
Expand Down