Skip to content

Commit

Permalink
Split node_id_or_metric endpoint into two parameters for node_id and …
Browse files Browse the repository at this point in the history
…metric for backwards-compatibility.

Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Aug 12, 2024
1 parent 52d3b22 commit 09157da
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions util/GenerateEndpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@

$params = [];
$parts = [];

// Iterate over the list of parameters and update them
foreach ($endpoint["parameters"] as $param_ref) {
$param_ref_value = substr($param_ref["$"."ref"], strrpos($param_ref["$"."ref"], '/') + 1);
Expand Down Expand Up @@ -137,13 +138,15 @@
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;
}
Expand Down Expand Up @@ -197,9 +200,26 @@

$parts_new[$part['name']] = $parts_dict;
}

if (!empty($parts_new)) {
$endpoint['parts'] = $parts_new;
}

if ($endpoint['x-operation-group'] === 'nodes.info' && $endpoint['path'] == '/_nodes/{node_id_or_metric}') {
# add two more endpoints, one for just node id and another for just metric for backwards compatibility
# https://github.com/opensearch-project/opensearch-api-specification/pull/416
foreach ([
'metric' => 'Limits the information returned to the specific metrics. Supports a comma-separated list, such as http,ingest.',
'node_id' => 'Comma-separated list of node IDs or names used to limit returned information.'
] as $param => $desc) {
$endpoint_new = $endpoint;
$endpoint_new['path'] = '/_nodes/{'.$param.'}';
$endpoint_new['parameters'][0] = ['$'.'ref' => '#/components/parameters/nodes.info::path.'.$param];
$endpoint_new['parts'] = [$param => [ 'type' => 'array', 'description' => $desc]];
$list_of_dicts[] = $endpoint_new;
}
}

$list_of_dicts[$index] = $endpoint;
}
}
Expand Down

0 comments on commit 09157da

Please sign in to comment.