Skip to content

Commit

Permalink
Generate API.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Aug 12, 2024
1 parent ddee7f3 commit 27810f2
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 54 deletions.
102 changes: 50 additions & 52 deletions src/OpenSearch/Namespaces/SqlNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,6 @@ public function close(array $params = [])

return $this->performRequest($endpoint);

Check warning on line 50 in src/OpenSearch/Namespaces/SqlNamespace.php

View check run for this annotation

Codecov / codecov/patch

src/OpenSearch/Namespaces/SqlNamespace.php#L50

Added line #L50 was not covered by tests
}
/**
* Shows how a query is executed against OpenSearch.
*
* $params['format'] = (string) A short version of the Accept header, e.g. json, yaml.
* $params['sanitize'] = (boolean) Specifies whether to escape special characters in the results (Default = true)
* $params['pretty'] = (boolean) Whether to pretty format the returned JSON response.
* $params['human'] = (boolean) Whether to return human readable values for statistics.
* $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors.
* $params['source'] = (string) The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests.
* $params['filter_path'] = (any) Comma-separated list of filters used to reduce the response.
*
* @param array $params Associative array of parameters
* @return array
*/
public function explain(array $params = [])
{
$body = $this->extractArgument($params, 'body');

$endpointBuilder = $this->endpoints;
$endpoint = $endpointBuilder('Sql\Explain');
$endpoint->setParams($params);
$endpoint->setBody($body);

return $this->performRequest($endpoint);
}
/**
* Collect metrics for the plugin within the interval.
*
Expand Down Expand Up @@ -121,31 +96,6 @@ public function postStats(array $params = [])

return $this->performRequest($endpoint);

Check warning on line 97 in src/OpenSearch/Namespaces/SqlNamespace.php

View check run for this annotation

Codecov / codecov/patch

src/OpenSearch/Namespaces/SqlNamespace.php#L97

Added line #L97 was not covered by tests
}
/**
* Send a SQL/PPL query to the SQL plugin.
*
* $params['format'] = (string) A short version of the Accept header, e.g. json, yaml.
* $params['sanitize'] = (boolean) Specifies whether to escape special characters in the results (Default = true)
* $params['pretty'] = (boolean) Whether to pretty format the returned JSON response.
* $params['human'] = (boolean) Whether to return human readable values for statistics.
* $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors.
* $params['source'] = (string) The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests.
* $params['filter_path'] = (any) Comma-separated list of filters used to reduce the response.
*
* @param array $params Associative array of parameters
* @return array
*/
public function query(array $params = [])
{
$body = $this->extractArgument($params, 'body');

$endpointBuilder = $this->endpoints;
$endpoint = $endpointBuilder('Sql\Query');
$endpoint->setParams($params);
$endpoint->setBody($body);

return $this->performRequest($endpoint);
}
/**
* Adds SQL settings to the standard OpenSearch cluster settings.
*
Expand All @@ -170,9 +120,7 @@ public function settings(array $params = [])

return $this->performRequest($endpoint);

Check warning on line 121 in src/OpenSearch/Namespaces/SqlNamespace.php

View check run for this annotation

Codecov / codecov/patch

src/OpenSearch/Namespaces/SqlNamespace.php#L121

Added line #L121 was not covered by tests
} /**
* Proxy function to closeCursor() to prevent BC break.
* This API will be removed in a future version. Use 'close' API instead.
* Note that the SQL close API takes the cursor in the body.
*
* $params['cursor'] = (string) The cursor given by the server
*
Expand All @@ -190,6 +138,56 @@ public function closeCursor(array $params): array
]));
$endpoint->setParams($params);

Check failure on line 139 in src/OpenSearch/Namespaces/SqlNamespace.php

View workflow job for this annotation

GitHub Actions / PHPStan

Call to method setParams() on an unknown class OpenSearch\Namespaces\AbstractEndpoint.

Check failure on line 139 in src/OpenSearch/Namespaces/SqlNamespace.php

View workflow job for this annotation

GitHub Actions / PHPStan

Call to method setParams() on an unknown class OpenSearch\Namespaces\AbstractEndpoint.

return $this->performRequest($endpoint);

Check failure on line 141 in src/OpenSearch/Namespaces/SqlNamespace.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $endpoint of method OpenSearch\Namespaces\AbstractNamespace::performRequest() expects OpenSearch\Endpoints\AbstractEndpoint, OpenSearch\Namespaces\AbstractEndpoint given.

Check failure on line 141 in src/OpenSearch/Namespaces/SqlNamespace.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $endpoint of method OpenSearch\Namespaces\AbstractNamespace::performRequest() expects OpenSearch\Endpoints\AbstractEndpoint, OpenSearch\Namespaces\AbstractEndpoint given.
} /**
* $params['query'] = (string) The SQL Query
*
* @param array{'query': string} $params Associative array of parameters
* @return array
*
* Note: Use of query parameter is deprecated. Pass it in `body` instead.
*/
public function explain(array $params): array
{
$endpointBuilder = $this->endpoints;

$body = $this->extractArgument($params, 'body') ?? [];
$query = $this->extractArgument($params, 'query');

/** @var AbstractEndpoint $endpoint */
$endpoint = $endpointBuilder('Sql\Explain');

Check failure on line 158 in src/OpenSearch/Namespaces/SqlNamespace.php

View workflow job for this annotation

GitHub Actions / PHPStan

PHPDoc tag @var for variable $endpoint contains unknown class OpenSearch\Namespaces\AbstractEndpoint.

Check failure on line 158 in src/OpenSearch/Namespaces/SqlNamespace.php

View workflow job for this annotation

GitHub Actions / PHPStan

PHPDoc tag @var for variable $endpoint contains unknown class OpenSearch\Namespaces\AbstractEndpoint.
$endpoint->setBody(array_merge($body, [

Check failure on line 159 in src/OpenSearch/Namespaces/SqlNamespace.php

View workflow job for this annotation

GitHub Actions / PHPStan

Call to method setBody() on an unknown class OpenSearch\Namespaces\AbstractEndpoint.

Check failure on line 159 in src/OpenSearch/Namespaces/SqlNamespace.php

View workflow job for this annotation

GitHub Actions / PHPStan

Call to method setBody() on an unknown class OpenSearch\Namespaces\AbstractEndpoint.
'query' => $query,
]));
$endpoint->setParams($params);

Check failure on line 162 in src/OpenSearch/Namespaces/SqlNamespace.php

View workflow job for this annotation

GitHub Actions / PHPStan

Call to method setParams() on an unknown class OpenSearch\Namespaces\AbstractEndpoint.

Check failure on line 162 in src/OpenSearch/Namespaces/SqlNamespace.php

View workflow job for this annotation

GitHub Actions / PHPStan

Call to method setParams() on an unknown class OpenSearch\Namespaces\AbstractEndpoint.

return $this->performRequest($endpoint);

Check failure on line 164 in src/OpenSearch/Namespaces/SqlNamespace.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $endpoint of method OpenSearch\Namespaces\AbstractNamespace::performRequest() expects OpenSearch\Endpoints\AbstractEndpoint, OpenSearch\Namespaces\AbstractEndpoint given.

Check failure on line 164 in src/OpenSearch/Namespaces/SqlNamespace.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $endpoint of method OpenSearch\Namespaces\AbstractNamespace::performRequest() expects OpenSearch\Endpoints\AbstractEndpoint, OpenSearch\Namespaces\AbstractEndpoint given.
} /**
* $params['query'] = (string) The SQL Query
* $params['format'] = (string) The response format
* $params['cursor'] = (string) The cursor given by the server
* $params['fetch_size'] = (int) The fetch size
*
* @param array{'query'?: string, 'cursor'?: string, 'fetch_size'?: int} $params Associative array of parameters
* @return array
*
* Note: Use of `query`, `cursor` and `fetch_size` parameters is deprecated. Pass them in `body` instead.
*
*/
public function query(array $params): array
{
$endpointBuilder = $this->endpoints;

/** @var AbstractEndpoint $endpoint */
$endpoint = $endpointBuilder('Sql\Query');

Check failure on line 182 in src/OpenSearch/Namespaces/SqlNamespace.php

View workflow job for this annotation

GitHub Actions / PHPStan

PHPDoc tag @var for variable $endpoint contains unknown class OpenSearch\Namespaces\AbstractEndpoint.

Check failure on line 182 in src/OpenSearch/Namespaces/SqlNamespace.php

View workflow job for this annotation

GitHub Actions / PHPStan

PHPDoc tag @var for variable $endpoint contains unknown class OpenSearch\Namespaces\AbstractEndpoint.
$body = $this->extractArgument($params, 'body') ?? [];
$endpoint->setBody(array_merge($body, array_filter([

Check failure on line 184 in src/OpenSearch/Namespaces/SqlNamespace.php

View workflow job for this annotation

GitHub Actions / PHPStan

Call to method setBody() on an unknown class OpenSearch\Namespaces\AbstractEndpoint.

Check failure on line 184 in src/OpenSearch/Namespaces/SqlNamespace.php

View workflow job for this annotation

GitHub Actions / PHPStan

Call to method setBody() on an unknown class OpenSearch\Namespaces\AbstractEndpoint.
'query' => $this->extractArgument($params, 'query'),
'cursor' => $this->extractArgument($params, 'cursor'),
'fetch_size' => $this->extractArgument($params, 'fetch_size'),
])));
$endpoint->setParams($params);

return $this->performRequest($endpoint);
}
}
2 changes: 1 addition & 1 deletion util/EndpointProxies/sql/explainProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function explain(array $params): array
{
$endpointBuilder = $this->endpoints;
$body = $this->extractArgument($params, 'body');
$body = $this->extractArgument($params, 'body') ?? [];
$query = $this->extractArgument($params, 'query');
/** @var AbstractEndpoint $endpoint */
Expand Down
2 changes: 1 addition & 1 deletion util/EndpointProxies/sql/queryProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function query(array $params): array
/** @var AbstractEndpoint $endpoint */
$endpoint = $endpointBuilder('Sql\Query');
$body = $this->extractArgument($params, 'body');
$body = $this->extractArgument($params, 'body') ?? [];
$endpoint->setBody(array_merge($body, array_filter([
'query' => $this->extractArgument($params, 'query'),
'cursor' => $this->extractArgument($params, 'cursor'),
Expand Down

0 comments on commit 27810f2

Please sign in to comment.