From 96580ebe8d0e9555a1a788d5ae62ca1d84ad5e0c Mon Sep 17 00:00:00 2001 From: Sai Medhini Reddy Maryada <117196660+saimedhi@users.noreply.github.com> Date: Mon, 8 Jul 2024 07:22:26 -0700 Subject: [PATCH] Fix generator and add proxies/patches for backward compatibility (#204) Signed-off-by: saimedhi --- util/ClientEndpoint.php | 13 ++++ util/Endpoint.php | 24 ++++--- .../createPointInTimeProxy.php | 13 ++++ .../deletePointInTimeProxy.php | 13 ++++ .../security/changePasswordProxy.php | 36 ++++++++++ .../security/createActionGroupProxy.php | 37 +++++++++++ .../security/createRoleMappingProxy.php | 41 ++++++++++++ .../security/createRoleProxy.php | 41 ++++++++++++ .../security/createTenantProxy.php | 37 +++++++++++ .../security/createUserProxy.php | 43 ++++++++++++ .../deleteDistinguishedNamesProxy.php | 13 ++++ .../security/getAccountProxy.php | 13 ++++ .../security/getActionGroupsProxy.php | 33 ++++++++++ .../security/getConfigProxy.php | 13 ++++ .../security/getDistinguishedNamesProxy.php | 34 ++++++++++ .../security/getRoleMappingsProxy.php | 33 ++++++++++ .../security/getRolesProxy.php | 33 ++++++++++ .../security/getTenantsProxy.php | 33 ++++++++++ .../security/getUsersProxy.php | 35 ++++++++++ .../security/patchActionGroupsProxy.php | 39 +++++++++++ .../security/patchConfigProxy.php | 17 +++++ .../security/patchRoleMappingsProxy.php | 38 +++++++++++ .../security/patchRolesProxy.php | 39 +++++++++++ .../security/patchTenantsProxy.php | 39 +++++++++++ .../security/patchUsersProxy.php | 39 +++++++++++ .../security/updateConfigProxy.php | 15 +++++ .../updateDistinguishedNamesProxy.php | 13 ++++ util/GenerateEndpoints.php | 65 ++++++++++++++++++- util/NamespaceEndpoint.php | 9 ++- util/template/client-class | 23 +++++-- util/template/endpoint-bulk-class | 3 + util/template/endpoint-class | 3 + 32 files changed, 862 insertions(+), 18 deletions(-) create mode 100644 util/EndpointProxies/createPointInTimeProxy.php create mode 100644 util/EndpointProxies/deletePointInTimeProxy.php create mode 100644 util/EndpointProxies/security/changePasswordProxy.php create mode 100644 util/EndpointProxies/security/createActionGroupProxy.php create mode 100644 util/EndpointProxies/security/createRoleMappingProxy.php create mode 100644 util/EndpointProxies/security/createRoleProxy.php create mode 100644 util/EndpointProxies/security/createTenantProxy.php create mode 100644 util/EndpointProxies/security/createUserProxy.php create mode 100644 util/EndpointProxies/security/deleteDistinguishedNamesProxy.php create mode 100644 util/EndpointProxies/security/getAccountProxy.php create mode 100644 util/EndpointProxies/security/getActionGroupsProxy.php create mode 100644 util/EndpointProxies/security/getConfigProxy.php create mode 100644 util/EndpointProxies/security/getDistinguishedNamesProxy.php create mode 100644 util/EndpointProxies/security/getRoleMappingsProxy.php create mode 100644 util/EndpointProxies/security/getRolesProxy.php create mode 100644 util/EndpointProxies/security/getTenantsProxy.php create mode 100644 util/EndpointProxies/security/getUsersProxy.php create mode 100644 util/EndpointProxies/security/patchActionGroupsProxy.php create mode 100644 util/EndpointProxies/security/patchConfigProxy.php create mode 100644 util/EndpointProxies/security/patchRoleMappingsProxy.php create mode 100644 util/EndpointProxies/security/patchRolesProxy.php create mode 100644 util/EndpointProxies/security/patchTenantsProxy.php create mode 100644 util/EndpointProxies/security/patchUsersProxy.php create mode 100644 util/EndpointProxies/security/updateConfigProxy.php create mode 100644 util/EndpointProxies/security/updateDistinguishedNamesProxy.php diff --git a/util/ClientEndpoint.php b/util/ClientEndpoint.php index 14a3920c..58835109 100644 --- a/util/ClientEndpoint.php +++ b/util/ClientEndpoint.php @@ -48,6 +48,12 @@ public function renderClass(): string $class = file_get_contents(self::CLIENT_CLASS_TEMPLATE); // use Namespace $useNamespace = ''; + + // The following namespaces do not have OpenSearch API specifications + $patchnamespaces = ['async_search', 'searchable_snapshots', 'ssl', 'sql', 'data_frame_transform_deprecated', 'monitoring']; + $this->namespace = array_unique(array_merge($this->namespace, $patchnamespaces)); + sort($this->namespace); + foreach ($this->namespace as $name) { if (empty($name)) { continue; @@ -89,6 +95,13 @@ public function renderClass(): string foreach ($this->endpoints as $endpoint) { $endpoints .= $this->renderEndpoint($endpoint); } + $proxyFolder = 'util/endpointproxies/'; + if (is_dir($proxyFolder)) { + $proxyFiles = glob($proxyFolder . '/*.php'); + foreach ($proxyFiles as $file) { + $endpoints .= require $file; + } + } $class = str_replace(':endpoints', $endpoints, $class); // Namespace functions diff --git a/util/Endpoint.php b/util/Endpoint.php index a23d0359..c91ab10f 100644 --- a/util/Endpoint.php +++ b/util/Endpoint.php @@ -94,7 +94,7 @@ public function __construct( $this->content = $this->content[$this->apiName]; $this->parts = $this->getPartsFromContent($this->content); - $this->requiredParts = $this->getRequiredParts($this->content); + $this->requiredParts = $this->getRequiredParts($this->content, $this->namespace); } public function getParts(): array @@ -113,7 +113,7 @@ private function getPartsFromContent(array $content): array return $parts; } - private function getRequiredParts(array $content): array + private function getRequiredParts(array $content, string $namespace): array { $required = []; // Get the list of required parts @@ -122,7 +122,8 @@ private function getRequiredParts(array $content): array } if (count($required) > 1) { return call_user_func_array('array_intersect', $required); - } elseif (count($required) === 1) { + } + if (empty($namespace) && !empty($required)) { return $required[0]; } return $required; @@ -158,18 +159,20 @@ public function renderClass(): string : '\\' . $this->normalizeName($this->namespace), $class ); + $class = isset($this->content['deprecation_message']) + ? str_replace(':deprecation-message', $this->content['deprecation_message'], $class) + : preg_replace('/\s*\/\*\*\s+\*\s+@deprecated :deprecation-message\s+\*\//', '', $class); // Set the HTTP method $action = $this->getMethod(); if ($action === ['POST', 'PUT'] && $this->getClassName() !== 'Bulk') { $method = "'PUT'"; + } elseif (!empty($this->content['body']) && ($action === ['GET', 'POST'] || $action === ['POST', 'GET'])) { + $method = 'isset($this->body) ? \'POST\' : \'GET\''; + } elseif ($this->getClassName() == "Refresh" || $this->getClassName() == "Flush") { + $method = "'POST'"; } else { - if (!empty($this->content['body']) && - ($action === ['GET', 'POST'] || $action === ['POST', 'GET'])) { - $method = 'isset($this->body) ? \'POST\' : \'GET\''; - } else { - $method = sprintf("'%s'", reset($action)); - } + $method = sprintf("'%s'", reset($action)); } $class = str_replace(':method', $method, $class); @@ -210,7 +213,8 @@ public function renderClass(): string $EndpointName = $this->getClassName(); if (!empty($this->namespace)) { - $filePath = $baseDir . "/src/OpenSearch/Endpoints/$this->namespace/$EndpointName.php"; + $namespace = str_replace('_', '', ucwords($this->namespace, '_')); + $filePath = $baseDir . "/src/OpenSearch/Endpoints/$namespace/$EndpointName.php"; } else { $filePath = $baseDir . "/src/OpenSearch/Endpoints/$EndpointName.php"; } diff --git a/util/EndpointProxies/createPointInTimeProxy.php b/util/EndpointProxies/createPointInTimeProxy.php new file mode 100644 index 00000000..12cc71b3 --- /dev/null +++ b/util/EndpointProxies/createPointInTimeProxy.php @@ -0,0 +1,13 @@ +createPit($params); +} +EOD; diff --git a/util/EndpointProxies/deletePointInTimeProxy.php b/util/EndpointProxies/deletePointInTimeProxy.php new file mode 100644 index 00000000..77d88d63 --- /dev/null +++ b/util/EndpointProxies/deletePointInTimeProxy.php @@ -0,0 +1,13 @@ +deletePit($params); +} +EOD; diff --git a/util/EndpointProxies/security/changePasswordProxy.php b/util/EndpointProxies/security/changePasswordProxy.php new file mode 100644 index 00000000..65d548d4 --- /dev/null +++ b/util/EndpointProxies/security/changePasswordProxy.php @@ -0,0 +1,36 @@ +extractArgument($params, 'body'); + if ($body ===null) { + $body =[ + 'current_password' => $this->extractArgument($params, 'current_password'), + 'password' => $this->extractArgument($params, 'password'), + ]; + } + + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\ChangePassword'); + $endpoint->setParams($params); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); +} +EOD; diff --git a/util/EndpointProxies/security/createActionGroupProxy.php b/util/EndpointProxies/security/createActionGroupProxy.php new file mode 100644 index 00000000..adebb27a --- /dev/null +++ b/util/EndpointProxies/security/createActionGroupProxy.php @@ -0,0 +1,37 @@ +extractArgument($params, 'action_group'); + $body = $this->extractArgument($params, 'body'); + if ($body ===null) { + $body =[ + 'allowed_actions' => $this->extractArgument($params, 'allowed_actions'), + ]; + } + + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\CreateActionGroup'); + $endpoint->setParams($params); + $endpoint->setActionGroup($action_group); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } +EOD; diff --git a/util/EndpointProxies/security/createRoleMappingProxy.php b/util/EndpointProxies/security/createRoleMappingProxy.php new file mode 100644 index 00000000..20635a66 --- /dev/null +++ b/util/EndpointProxies/security/createRoleMappingProxy.php @@ -0,0 +1,41 @@ +extractArgument($params, 'role'); + $body = $this->extractArgument($params, 'body'); + if ($body ===null) { + $body = array_filter([ + 'backend_roles' => $this->extractArgument($params, 'backend_roles'), + 'hosts' => $this->extractArgument($params, 'hosts'), + 'users' => $this->extractArgument($params, 'users'), + ]); + } + + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\CreateRoleMapping'); + $endpoint->setParams($params); + $endpoint->setRole($role); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); +} +EOD; diff --git a/util/EndpointProxies/security/createRoleProxy.php b/util/EndpointProxies/security/createRoleProxy.php new file mode 100644 index 00000000..06d468e0 --- /dev/null +++ b/util/EndpointProxies/security/createRoleProxy.php @@ -0,0 +1,41 @@ +extractArgument($params, 'role'); + $body = $this->extractArgument($params, 'body'); + if ($body ===null) { + $body = array_filter([ + 'cluster_permissions' => $this->extractArgument($params, 'cluster_permissions'), + 'index_permissions' => $this->extractArgument($params, 'index_permissions'), + 'tenant_permissions' => $this->extractArgument($params, 'tenant_permissions'), + ]); + } + + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\CreateRole'); + $endpoint->setParams($params); + $endpoint->setRole($role); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); +} +EOD; diff --git a/util/EndpointProxies/security/createTenantProxy.php b/util/EndpointProxies/security/createTenantProxy.php new file mode 100644 index 00000000..da84477a --- /dev/null +++ b/util/EndpointProxies/security/createTenantProxy.php @@ -0,0 +1,37 @@ +extractArgument($params, 'tenant'); + $body = $this->extractArgument($params, 'body'); + if ($body ===null) { + $body = [ + 'description' => $this->extractArgument($params, 'description'), + ]; + } + + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\CreateTenant'); + $endpoint->setParams($params); + $endpoint->setTenant($tenant); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); +} +EOD; diff --git a/util/EndpointProxies/security/createUserProxy.php b/util/EndpointProxies/security/createUserProxy.php new file mode 100644 index 00000000..77d22c02 --- /dev/null +++ b/util/EndpointProxies/security/createUserProxy.php @@ -0,0 +1,43 @@ +extractArgument($params, 'username'); + $body = $this->extractArgument($params, 'body'); + if ($body ===null) { + $body = array_filter([ + 'password' => $this->extractArgument($params, 'password'), + 'opendistro_security_roles' => $this->extractArgument($params, 'opendistro_security_roles'), + 'backend_roles' => $this->extractArgument($params, 'backend_roles'), + 'attributes' => $this->extractArgument($params, 'attributes'), + ]); + } + + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\CreateUser'); + $endpoint->setParams($params); + $endpoint->setUsername($username); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } +EOD; diff --git a/util/EndpointProxies/security/deleteDistinguishedNamesProxy.php b/util/EndpointProxies/security/deleteDistinguishedNamesProxy.php new file mode 100644 index 00000000..c0b83205 --- /dev/null +++ b/util/EndpointProxies/security/deleteDistinguishedNamesProxy.php @@ -0,0 +1,13 @@ +deleteDistinguishedName($params); +} +EOD; diff --git a/util/EndpointProxies/security/getAccountProxy.php b/util/EndpointProxies/security/getAccountProxy.php new file mode 100644 index 00000000..c5445894 --- /dev/null +++ b/util/EndpointProxies/security/getAccountProxy.php @@ -0,0 +1,13 @@ +getAccountDetails($params); +} +EOD; diff --git a/util/EndpointProxies/security/getActionGroupsProxy.php b/util/EndpointProxies/security/getActionGroupsProxy.php new file mode 100644 index 00000000..2b09a8b6 --- /dev/null +++ b/util/EndpointProxies/security/getActionGroupsProxy.php @@ -0,0 +1,33 @@ +endpoints; + if (isset($params['action_group'])) { + $endpoint = $endpointBuilder('Security\GetActionGroup'); + $endpoint->setActionGroup($params['action_group']); + unset($params['action_group']); + } else { + $endpoint = $endpointBuilder('Security\GetActionGroups'); + } + $endpoint = $endpointBuilder('Security\GetActionGroups'); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); +} +EOD; diff --git a/util/EndpointProxies/security/getConfigProxy.php b/util/EndpointProxies/security/getConfigProxy.php new file mode 100644 index 00000000..cf1f2ccd --- /dev/null +++ b/util/EndpointProxies/security/getConfigProxy.php @@ -0,0 +1,13 @@ +getConfiguration($params); +} +EOD; diff --git a/util/EndpointProxies/security/getDistinguishedNamesProxy.php b/util/EndpointProxies/security/getDistinguishedNamesProxy.php new file mode 100644 index 00000000..2fc71d1f --- /dev/null +++ b/util/EndpointProxies/security/getDistinguishedNamesProxy.php @@ -0,0 +1,34 @@ +endpoints; + if (isset($params['cluster_name'])) { + $endpoint = $endpointBuilder('Security\GetDistinguishedName'); + $endpoint->setClusterName($params['cluster_name']); + unset($params['cluster_name']); + } else { + $endpoint = $endpointBuilder('Security\GetDistinguishedNames'); + } + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } +EOD; diff --git a/util/EndpointProxies/security/getRoleMappingsProxy.php b/util/EndpointProxies/security/getRoleMappingsProxy.php new file mode 100644 index 00000000..44f1710a --- /dev/null +++ b/util/EndpointProxies/security/getRoleMappingsProxy.php @@ -0,0 +1,33 @@ +endpoints; + if (isset($params['role'])) { + $endpoint = $endpointBuilder('Security\GetRoleMapping'); + $endpoint->setRole($params['role']); + unset($params['role']); + } else { + $endpoint = $endpointBuilder('Security\GetRoleMappings'); + } + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } +EOD; diff --git a/util/EndpointProxies/security/getRolesProxy.php b/util/EndpointProxies/security/getRolesProxy.php new file mode 100644 index 00000000..eba22b91 --- /dev/null +++ b/util/EndpointProxies/security/getRolesProxy.php @@ -0,0 +1,33 @@ +endpoints; + if (isset($params['role'])) { + $endpoint = $endpointBuilder('Security\GetRole'); + $endpoint->setRole($params['role']); + unset($params['role']); + } else { + $endpoint = $endpointBuilder('Security\GetRoles'); + } + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } +EOD; diff --git a/util/EndpointProxies/security/getTenantsProxy.php b/util/EndpointProxies/security/getTenantsProxy.php new file mode 100644 index 00000000..e36e6640 --- /dev/null +++ b/util/EndpointProxies/security/getTenantsProxy.php @@ -0,0 +1,33 @@ +endpoints; + if (isset($params['tenant'])) { + $endpoint = $endpointBuilder('Security\GetTenant'); + $endpoint->setTenant($params['tenant']); + unset($params['tenant']); + } else { + $endpoint = $endpointBuilder('Security\GetTenants'); + } + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } +EOD; diff --git a/util/EndpointProxies/security/getUsersProxy.php b/util/EndpointProxies/security/getUsersProxy.php new file mode 100644 index 00000000..8209b6f5 --- /dev/null +++ b/util/EndpointProxies/security/getUsersProxy.php @@ -0,0 +1,35 @@ +endpoints; + + if (isset($params['username'])) { + $endpoint = $endpointBuilder('Security\GetUser'); + $endpoint->setUsername($params['username']); + unset($params['username']); + } else { + $endpoint = $endpointBuilder('Security\GetUsers'); + } + + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } +EOD; diff --git a/util/EndpointProxies/security/patchActionGroupsProxy.php b/util/EndpointProxies/security/patchActionGroupsProxy.php new file mode 100644 index 00000000..1a8b3f28 --- /dev/null +++ b/util/EndpointProxies/security/patchActionGroupsProxy.php @@ -0,0 +1,39 @@ +extractArgument($params, 'body'); + + if ($body ===null) { + $body = $this->extractArgument($params, 'ops') ?? []; + } + + $endpointBuilder = $this->endpoints; + if (isset($params['action_group'])) { + $endpoint = $endpointBuilder('Security\PatchActionGroup'); + $endpoint->setActionGroup($params['action_group']); + unset($params['action_group']); + } else { + $endpoint = $endpointBuilder('Security\PatchActionGroups'); + } + $endpoint->setParams($params); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } + +EOD; diff --git a/util/EndpointProxies/security/patchConfigProxy.php b/util/EndpointProxies/security/patchConfigProxy.php new file mode 100644 index 00000000..0ce6c9be --- /dev/null +++ b/util/EndpointProxies/security/patchConfigProxy.php @@ -0,0 +1,17 @@ +extractArgument($params, 'ops'); + if ($ops !== null) { + $params['body'] = $ops; + } + return $this->patchConfiguration($params); +} +EOD; diff --git a/util/EndpointProxies/security/patchRoleMappingsProxy.php b/util/EndpointProxies/security/patchRoleMappingsProxy.php new file mode 100644 index 00000000..b1b89656 --- /dev/null +++ b/util/EndpointProxies/security/patchRoleMappingsProxy.php @@ -0,0 +1,38 @@ +extractArgument($params, 'body'); + if ($body === null) { + $body = $this->extractArgument($params, 'ops') ?? []; + } + + $endpointBuilder = $this->endpoints; + if (isset($params['role'])) { + $endpoint = $endpointBuilder('Security\PatchRoleMapping'); + $endpoint->setRole($params['role']); + unset($params['role']); + } else { + $endpoint = $endpointBuilder('Security\PatchRoleMappings'); + } + $endpoint->setParams($params); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } +EOD; diff --git a/util/EndpointProxies/security/patchRolesProxy.php b/util/EndpointProxies/security/patchRolesProxy.php new file mode 100644 index 00000000..3428bf30 --- /dev/null +++ b/util/EndpointProxies/security/patchRolesProxy.php @@ -0,0 +1,39 @@ +extractArgument($params, 'body'); + if ($body ===null) { + $body = $this->extractArgument($params, 'ops') ?? []; + } + + $endpointBuilder = $this->endpoints; + if (isset($params['role'])) { + $endpoint = $endpointBuilder('Security\PatchRole'); + $endpoint->setRole($params['role']); + unset($params['role']); + } else { + $endpoint = $endpointBuilder('Security\PatchRoles'); + } + + $endpoint->setParams($params); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } +EOD; diff --git a/util/EndpointProxies/security/patchTenantsProxy.php b/util/EndpointProxies/security/patchTenantsProxy.php new file mode 100644 index 00000000..4ca52dc1 --- /dev/null +++ b/util/EndpointProxies/security/patchTenantsProxy.php @@ -0,0 +1,39 @@ +extractArgument($params, 'body'); + if ($body ===null) { + $body = $this->extractArgument($params, 'ops') ?? []; + } + + $endpointBuilder = $this->endpoints; + if (isset($params['tenant'])) { + $endpoint = $endpointBuilder('Security\PatchTenant'); + $endpoint->setTenant($params['tenant']); + unset($params['tenant']); + } else { + $endpoint = $endpointBuilder('Security\PatchTenants'); + } + + $endpoint->setParams($params); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } +EOD; diff --git a/util/EndpointProxies/security/patchUsersProxy.php b/util/EndpointProxies/security/patchUsersProxy.php new file mode 100644 index 00000000..95ae5299 --- /dev/null +++ b/util/EndpointProxies/security/patchUsersProxy.php @@ -0,0 +1,39 @@ +extractArgument($params, 'body'); + if ($body ===null) { + $body = $this->extractArgument($params, 'ops') ?? []; + } + + $endpointBuilder = $this->endpoints; + if (isset($params['username'])) { + $endpoint = $endpointBuilder('Security\PatchUser'); + $endpoint->setUsername($params['username']); + unset($params['username']); + } else { + $endpoint = $endpointBuilder('Security\PatchUsers'); + } + + $endpoint->setParams($params); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } +EOD; diff --git a/util/EndpointProxies/security/updateConfigProxy.php b/util/EndpointProxies/security/updateConfigProxy.php new file mode 100644 index 00000000..1e57a052 --- /dev/null +++ b/util/EndpointProxies/security/updateConfigProxy.php @@ -0,0 +1,15 @@ + $this->extractArgument($params, 'dynamic')]; + $params['body'] = $body; + return $this->updateConfiguration($params); +} +EOD; diff --git a/util/EndpointProxies/security/updateDistinguishedNamesProxy.php b/util/EndpointProxies/security/updateDistinguishedNamesProxy.php new file mode 100644 index 00000000..d619d5c9 --- /dev/null +++ b/util/EndpointProxies/security/updateDistinguishedNamesProxy.php @@ -0,0 +1,13 @@ +updateDistinguishedName($params); +} +EOD; diff --git a/util/GenerateEndpoints.php b/util/GenerateEndpoints.php index 57dcb6ae..e9637595 100644 --- a/util/GenerateEndpoints.php +++ b/util/GenerateEndpoints.php @@ -45,6 +45,11 @@ foreach ($data["paths"] as $path => $pathDetails) { foreach ($pathDetails as $method => $methodDetails) { + if (isset($methodDetails["x-operation-group"]) && $methodDetails["x-operation-group"] == "nodes.hot_threads") { + if (isset($methodDetails["deprecated"]) && $methodDetails["deprecated"]) { + continue; + } + } $methodDetails["path"] = $path; $methodDetails["method"] = $method; $list_of_dicts[] = $methodDetails; @@ -132,6 +137,13 @@ if ($endpoint['x-operation-group'] !== 'nodes.hot_threads' && isset($params_new['type'])) { unset($params_new['type']); } + if ($endpoint['x-operation-group'] === 'cat.tasks') { + $params_new['node_id'] = $params_new['nodes'] ?? $params_new['node_id']; + unset($params_new['nodes']); + + $params_new['parent_task'] = $params_new['parent_task_id'] ?? $params_new['parent_task']; + unset($params_new['parent_task_id']); + } if (!empty($params_new)) { $endpoint['params'] = $params_new; } @@ -145,10 +157,16 @@ foreach ($part['schema']['oneOf'] as $item) { if (isset($item['type'])) { $parts_dict['type'] = $item['type']; - break; + if ($item['type'] == "array") { + break; + } } } } + if ($endpoint['x-operation-group'] === 'cluster.get_component_template' || $endpoint['x-operation-group'] === 'indices.get_index_template') { + $part['name'] = "name"; + $parts_dict['type'] = 'array'; + } if (isset($part['description'])) { $parts_dict['description'] = str_replace("\n", " ", $part['description']); @@ -285,6 +303,9 @@ } $api['url'] = ['paths' => $paths]; + if ($all_paths_have_deprecation && $deprecated_path_dict !== null) { + $api['deprecation_message'] = $deprecated_path_dict['description']; + } $files[] = [$key => $api]; } // Generate endpoints @@ -358,6 +379,7 @@ $destDir = __DIR__ . "/../src/OpenSearch"; printf("Copying the generated files to %s\n", $destDir); +Patch_Endpoints(); cleanFolders(); fix_license_header($outputDir . "/Namespaces"); fix_license_header($outputDir . "/Endpoints"); @@ -479,3 +501,44 @@ function isValidPhpSyntax(string $filename): bool } return false; } + +/** + * Patching Endpoints that do not have OpenSearch API specifications + */ +function Patch_Endpoints() +{ + $patchEndpoints = ['AsyncSearch', 'SearchableSnapshots', 'Ssl', 'Sql', + 'DataFrameTransformDeprecated', 'Monitoring' ]; + $outputDir = __DIR__ . "/output"; + $destDir = __DIR__ . "/../src/OpenSearch"; + + $foldersToCheck = ['Endpoints', 'Namespaces']; + + foreach ($foldersToCheck as $folder) { + $dirPath = "$destDir/$folder"; + if (!is_dir($dirPath)) { + continue; + } + + $iterator = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($dirPath, RecursiveDirectoryIterator::SKIP_DOTS) + ); + + foreach ($iterator as $file) { + if ($file->isFile()) { + $filePath = $file->getPathname(); + foreach ($patchEndpoints as $endpoint) { + if (strpos($filePath, $endpoint) !== false) { + $relativePath = str_replace($destDir, '', $filePath); + $targetPath = $outputDir . $relativePath; + + if (!file_exists($targetPath)) { + is_dir(dirname($targetPath)) || mkdir(dirname($targetPath), 0777, true); + copy($filePath, $targetPath); + } + } + } + } + } + } +} diff --git a/util/NamespaceEndpoint.php b/util/NamespaceEndpoint.php index dab73515..976f42e5 100644 --- a/util/NamespaceEndpoint.php +++ b/util/NamespaceEndpoint.php @@ -68,13 +68,16 @@ public function renderClass(): string $endpoints = ''; foreach ($this->endpoints as $endpoint) { - $endpoints .= $this->renderEndpoint($endpoint); + $endpointName = $this->getEndpointName($endpoint->name); + $proxyFilePath = 'util/endpointproxies/' . $this->name . '/' . $endpointName . 'Proxy.php'; + if (!file_exists($proxyFilePath)) { + $endpoints .= $this->renderEndpoint($endpoint); + } } $proxyFolder = 'util/endpointproxies/' . $this->name; if (is_dir($proxyFolder)) { - $proxyFiles = glob($proxyFolder . '/*.php'); - foreach ($proxyFiles as $file) { + foreach (glob($proxyFolder . '/*Proxy.php') as $file) { $endpoints .= require $file; } } diff --git a/util/template/client-class b/util/template/client-class index d5dfc1a2..00a50673 100644 --- a/util/template/client-class +++ b/util/template/client-class @@ -24,7 +24,6 @@ namespace OpenSearch; use OpenSearch\Common\Exceptions\BadMethodCallException; use OpenSearch\Common\Exceptions\NoNodesAvailableException; use OpenSearch\Endpoints\AbstractEndpoint; -use OpenSearch\Namespaces\AbstractNamespace; use OpenSearch\Namespaces\NamespaceBuilderInterface; use OpenSearch\Namespaces\BooleanRequestWrapper; :use-namespaces @@ -61,9 +60,9 @@ class Client /** * Client constructor * - * @param Transport $transport - * @param callable $endpoint - * @param AbstractNamespace[] $registeredNamespaces + * @param Transport $transport + * @param callable $endpoint + * @param NamespaceBuilderInterface[] $registeredNamespaces */ public function __construct(Transport $transport, callable $endpoint, array $registeredNamespaces) { @@ -107,6 +106,22 @@ class Client } } + /** + * Sends a raw request to the cluster + * @return callable|array + * @throws NoNodesAvailableException + */ + public function request(string $method, string $uri, array $attributes = []) + { + $params = $attributes['params'] ?? []; + $body = $attributes['body'] ?? null; + $options = $attributes['options'] ?? []; + + $promise = $this->transport->performRequest($method, $uri, $params, $body, $options); + + return $this->transport->resultOrFuture($promise, $options); + } + /** * @return callable|array */ diff --git a/util/template/endpoint-bulk-class b/util/template/endpoint-bulk-class index af887e1e..2f83c81a 100644 --- a/util/template/endpoint-bulk-class +++ b/util/template/endpoint-bulk-class @@ -8,6 +8,9 @@ use OpenSearch\Endpoints\AbstractEndpoint; use OpenSearch\Serializers\SerializerInterface; use Traversable; +/** + * NOTE: This file is autogenerated using util/GenerateEndpoints.php + */ class :endpoint extends AbstractEndpoint { :properties diff --git a/util/template/endpoint-class b/util/template/endpoint-class index c8041540..c81b3daf 100644 --- a/util/template/endpoint-class +++ b/util/template/endpoint-class @@ -9,6 +9,9 @@ use OpenSearch\Endpoints\AbstractEndpoint; /** * NOTE: This file is autogenerated using util/GenerateEndpoints.php */ +/** + * @deprecated :deprecation-message + */ class :endpoint extends AbstractEndpoint { :properties