Skip to content

Commit

Permalink
Fix URI string generation logic. (#639) (#640)
Browse files Browse the repository at this point in the history
* Fix URI string generation logic.

Signed-off-by: AWSHurneyt <hurneyt@amazon.com>

* Updated test.

Signed-off-by: AWSHurneyt <hurneyt@amazon.com>

---------

Signed-off-by: AWSHurneyt <hurneyt@amazon.com>
(cherry picked from commit 043881b)

Co-authored-by: AWSHurneyt <hurneyt@amazon.com>
  • Loading branch information
opensearch-trigger-bot[bot] and AWSHurneyt authored Jul 14, 2023
1 parent 476c438 commit daa0fe0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('clusterMetricsMonitorHelpers', () => {
uri: {
api_type: API_TYPES.CLUSTER_HEALTH.type,
path: path,
path_params: pathParams,
path_params: '/' + pathParams,
url: `http://localhost:9200/${path}/${pathParams}`,
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,18 @@ export function formikToClusterMetricsInput(values) {
if (_.isEmpty(apiType)) apiType = getApiType(_.get(values, 'uri'));
let pathParams = _.get(values, 'uri.path_params', FORMIK_INITIAL_VALUES.uri.path_params);
pathParams = _.trim(pathParams);
// Trim '/' characters from the beginning and end of the path
pathParams = pathParams?.replace(/^\/+|\/+$/g, '');
const hasPathParams = !_.isEmpty(pathParams);
const path = getApiPath(hasPathParams, apiType);
let url = FORMIK_INITIAL_VALUES.uri.url;
if (!_.isEmpty(apiType)) {
url = URL_DEFAULT_PREFIX;
if (!_.isEmpty(path)) url = url + '/' + path;
if (hasPathParams) url = url + '/' + pathParams + _.get(API_TYPES, `${apiType}.appendText`, '');
if (hasPathParams) {
pathParams = '/' + pathParams;
url = url + pathParams + _.get(API_TYPES, `${apiType}.appendText`, '');
}
}
return {
uri: {
Expand Down

0 comments on commit daa0fe0

Please sign in to comment.