Skip to content
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

Fix node id vs. metric for backwards compatibility. #221

Merged
merged 1 commit into from
Aug 12, 2024
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
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
Loading