From fc20dcd443d06bc1f12d6515e9350feeb1f1b4ce Mon Sep 17 00:00:00 2001 From: TharmiganK Date: Sun, 22 Sep 2024 21:29:28 +0530 Subject: [PATCH] Fix test cases --- .../client/FunctionBodyNodeTests.java | 4 +-- .../default_headers_conflict_with_query.bal | 7 ++--- .../default_headers_queries_parameters.bal | 26 ++++--------------- .../default_value_generation_client.bal | 26 ++++--------------- .../expected_gen/jira_openapi_client.bal | 7 ++--- ...ils_for_both_service_client_generation.bal | 8 +++--- .../licenses/utils_for_client_generation.bal | 8 +++--- .../utils_for_with_user_given_license.bal | 8 +++--- .../petstore_catch_all_path_client.bal | 2 +- .../expected_gen/petstore_client_swagger.bal | 6 ++--- .../expected_gen/sanitize_array_member.bal | 26 ++++--------------- .../type_name_with_mixed_case.bal | 26 ++++--------------- .../src/test/resources/expected_gen/utils.bal | 8 +++--- .../combination_of_apikey_and_http_oauth.bal | 8 +++--- .../client/ballerina/delete_with_header.bal | 4 +-- .../ballerina/header_integer_signed32.bal | 2 +- .../client/ballerina/header_optional.bal | 2 +- .../header_param_with_default_value.bal | 2 +- .../client/ballerina/header_parameter.bal | 2 +- .../ballerina/header_without_parameter.bal | 2 +- .../client/ballerina/parameters_with_enum.bal | 2 +- .../parameters_with_nullable_enums.bal | 2 +- ...arameters_with_nullable_enums_resource.bal | 2 +- .../paramters_with_enum_resource.bal | 2 +- .../file_provider/ballerina/api2pdf.bal | 12 ++++----- .../ballerina/header_with_enum.bal | 2 +- .../ballerina/multiline_param_comment.bal | 2 +- .../client/resource/ballerina/header.bal | 4 +-- .../client/expected/project-09/client.bal | 4 +-- .../client/expected/project-09/utils.bal | 25 ++++-------------- .../client/project-expected/utils.bal | 8 +++--- .../client/project-expected/utils_all.bal | 8 +++--- .../utils_all_with_default.bal | 7 ++--- .../project-expected/utils_with_default.bal | 7 ++--- 34 files changed, 104 insertions(+), 167 deletions(-) diff --git a/openapi-cli/src/test/java/io/ballerina/openapi/generators/client/FunctionBodyNodeTests.java b/openapi-cli/src/test/java/io/ballerina/openapi/generators/client/FunctionBodyNodeTests.java index 495dcef27..5630b03b2 100644 --- a/openapi-cli/src/test/java/io/ballerina/openapi/generators/client/FunctionBodyNodeTests.java +++ b/openapi-cli/src/test/java/io/ballerina/openapi/generators/client/FunctionBodyNodeTests.java @@ -81,12 +81,12 @@ public Object[][] dataProviderForFunctionBody() { {"diagnostic_files/header_parameter.yaml", "/pets", true, false, false, "{string resourcePath=string`/pets`;" + "map" + - "httpHeaders=getMapForHeaders(headers);return self.clientEp->" + + "httpHeaders=http:getHeaderMap(headers);return self.clientEp->" + "get(resourcePath,httpHeaders);}"}, {"diagnostic_files/head_operation.yaml", "/{filesystem}", true, false, true, "{string resourcePath=string`/${getEncodedUri(filesystem)}`;" + "resourcePath = resourcePath + check getPathForQueryParam(queries);" + - "map httpHeaders = getMapForHeaders(headers);" + + "map httpHeaders = http:getHeaderMap(headers);" + "return self.clientEp-> head(resourcePath, httpHeaders);}"}, {"diagnostic_files/operation_delete.yaml", "/pets/{petId}", false, false, false, "{string resourcePath = " + diff --git a/openapi-cli/src/test/resources/expected_gen/default_headers_conflict_with_query.bal b/openapi-cli/src/test/resources/expected_gen/default_headers_conflict_with_query.bal index 637f63553..dd57d7110 100644 --- a/openapi-cli/src/test/resources/expected_gen/default_headers_conflict_with_query.bal +++ b/openapi-cli/src/test/resources/expected_gen/default_headers_conflict_with_query.bal @@ -216,12 +216,13 @@ isolated function getEncodedUri(anydata value) returns string { # + encodingMap - Details on serialization mechanism # + return - Returns generated Path or error at failure of client initialization isolated function getPathForQueryParam(map queryParam, map encodingMap = {}) returns string|error { + map queriesMap = http:getQueryMap(queryParam); string[] param = []; - if queryParam.length() > 0 { + if queriesMap.length() > 0 { param.push("?"); - foreach var [key, value] in queryParam.entries() { + foreach var [key, value] in queriesMap.entries() { if value is () { - _ = queryParam.remove(key); + _ = queriesMap.remove(key); continue; } Encoding encodingData = encodingMap.hasKey(key) ? encodingMap.get(key) : defaultEncoding; diff --git a/openapi-cli/src/test/resources/expected_gen/default_headers_queries_parameters.bal b/openapi-cli/src/test/resources/expected_gen/default_headers_queries_parameters.bal index c7dc3ec98..376268f53 100644 --- a/openapi-cli/src/test/resources/expected_gen/default_headers_queries_parameters.bal +++ b/openapi-cli/src/test/resources/expected_gen/default_headers_queries_parameters.bal @@ -45,7 +45,7 @@ public isolated client class Client { resource isolated function get albums/[int id](GetAlbumsIdHeaders headers = {}, *GetAlbumsIdQueries queries) returns record {}|error { string resourcePath = string `/albums/${getEncodedUri(id)}`; resourcePath = resourcePath + check getPathForQueryParam(queries); - map httpHeaders = getMapForHeaders(headers); + map httpHeaders = http:getHeaderMap(headers); return self.clientEp->get(resourcePath, httpHeaders); } } @@ -217,12 +217,13 @@ isolated function getEncodedUri(anydata value) returns string { # + encodingMap - Details on serialization mechanism # + return - Returns generated Path or error at failure of client initialization isolated function getPathForQueryParam(map queryParam, map encodingMap = {}) returns string|error { + map queriesMap = http:getQueryMap(queryParam); string[] param = []; - if queryParam.length() > 0 { + if queriesMap.length() > 0 { param.push("?"); - foreach var [key, value] in queryParam.entries() { + foreach var [key, value] in queriesMap.entries() { if value is () { - _ = queryParam.remove(key); + _ = queriesMap.remove(key); continue; } Encoding encodingData = encodingMap.hasKey(key) ? encodingMap.get(key) : defaultEncoding; @@ -247,23 +248,6 @@ isolated function getPathForQueryParam(map queryParam, map en return restOfPath; } -# Generate header map for given header values. -# -# + headerParam - Headers map -# + return - Returns generated map or error at failure of client initialization -isolated function getMapForHeaders(map headerParam) returns map { - map headerMap = {}; - foreach var [key, value] in headerParam.entries() { - if value is SimpleBasicType[] { - headerMap[key] = from SimpleBasicType data in value - select data.toString(); - } else { - headerMap[key] = value.toString(); - } - } - return headerMap; -} - # Provides settings related to HTTP/1.x protocol. public type ClientHttp1Settings record {| # Specifies whether to reuse a connection for multiple requests diff --git a/openapi-cli/src/test/resources/expected_gen/default_value_generation_client.bal b/openapi-cli/src/test/resources/expected_gen/default_value_generation_client.bal index 37ee40ce6..1771e5cbe 100644 --- a/openapi-cli/src/test/resources/expected_gen/default_value_generation_client.bal +++ b/openapi-cli/src/test/resources/expected_gen/default_value_generation_client.bal @@ -45,7 +45,7 @@ public isolated client class Client { resource isolated function get albums/[string id](GetAlbumsIdHeaders headers = {}, *GetAlbumsIdQueries queries) returns Album|error { string resourcePath = string `/albums/${getEncodedUri(id)}`; resourcePath = resourcePath + check getPathForQueryParam(queries); - map httpHeaders = getMapForHeaders(headers); + map httpHeaders = http:getHeaderMap(headers); return self.clientEp->get(resourcePath, httpHeaders); } } @@ -217,12 +217,13 @@ isolated function getEncodedUri(anydata value) returns string { # + encodingMap - Details on serialization mechanism # + return - Returns generated Path or error at failure of client initialization isolated function getPathForQueryParam(map queryParam, map encodingMap = {}) returns string|error { + map queriesMap = http:getQueryMap(queryParam); string[] param = []; - if queryParam.length() > 0 { + if queriesMap.length() > 0 { param.push("?"); - foreach var [key, value] in queryParam.entries() { + foreach var [key, value] in queriesMap.entries() { if value is () { - _ = queryParam.remove(key); + _ = queriesMap.remove(key); continue; } Encoding encodingData = encodingMap.hasKey(key) ? encodingMap.get(key) : defaultEncoding; @@ -247,23 +248,6 @@ isolated function getPathForQueryParam(map queryParam, map en return restOfPath; } -# Generate header map for given header values. -# -# + headerParam - Headers map -# + return - Returns generated map or error at failure of client initialization -isolated function getMapForHeaders(map headerParam) returns map { - map headerMap = {}; - foreach var [key, value] in headerParam.entries() { - if value is SimpleBasicType[] { - headerMap[key] = from SimpleBasicType data in value - select data.toString(); - } else { - headerMap[key] = value.toString(); - } - } - return headerMap; -} - # Provides settings related to HTTP/1.x protocol. public type ClientHttp1Settings record {| # Specifies whether to reuse a connection for multiple requests diff --git a/openapi-cli/src/test/resources/expected_gen/jira_openapi_client.bal b/openapi-cli/src/test/resources/expected_gen/jira_openapi_client.bal index e8f506f8a..a1219ac5f 100644 --- a/openapi-cli/src/test/resources/expected_gen/jira_openapi_client.bal +++ b/openapi-cli/src/test/resources/expected_gen/jira_openapi_client.bal @@ -2904,12 +2904,13 @@ isolated function getEncodedUri(anydata value) returns string { # + encodingMap - Details on serialization mechanism # + return - Returns generated Path or error at failure of client initialization isolated function getPathForQueryParam(map queryParam, map encodingMap = {}) returns string|error { + map queriesMap = http:getQueryMap(queryParam); string[] param = []; - if queryParam.length() > 0 { + if queriesMap.length() > 0 { param.push("?"); - foreach var [key, value] in queryParam.entries() { + foreach var [key, value] in queriesMap.entries() { if value is () { - _ = queryParam.remove(key); + _ = queriesMap.remove(key); continue; } Encoding encodingData = encodingMap.hasKey(key) ? encodingMap.get(key) : defaultEncoding; diff --git a/openapi-cli/src/test/resources/expected_gen/licenses/utils_for_both_service_client_generation.bal b/openapi-cli/src/test/resources/expected_gen/licenses/utils_for_both_service_client_generation.bal index 461d33b75..e470e3e51 100644 --- a/openapi-cli/src/test/resources/expected_gen/licenses/utils_for_both_service_client_generation.bal +++ b/openapi-cli/src/test/resources/expected_gen/licenses/utils_for_both_service_client_generation.bal @@ -1,6 +1,7 @@ // AUTO-GENERATED FILE. // This file is auto-generated by the Ballerina OpenAPI tool. +import ballerina/http; import ballerina/url; type SimpleBasicType string|boolean|int|float|decimal; @@ -170,12 +171,13 @@ isolated function getEncodedUri(anydata value) returns string { # + encodingMap - Details on serialization mechanism # + return - Returns generated Path or error at failure of client initialization isolated function getPathForQueryParam(map queryParam, map encodingMap = {}) returns string|error { + map queriesMap = http:getQueryMap(queryParam); string[] param = []; - if queryParam.length() > 0 { + if queriesMap.length() > 0 { param.push("?"); - foreach var [key, value] in queryParam.entries() { + foreach var [key, value] in queriesMap.entries() { if value is () { - _ = queryParam.remove(key); + _ = queriesMap.remove(key); continue; } Encoding encodingData = encodingMap.hasKey(key) ? encodingMap.get(key) : defaultEncoding; diff --git a/openapi-cli/src/test/resources/expected_gen/licenses/utils_for_client_generation.bal b/openapi-cli/src/test/resources/expected_gen/licenses/utils_for_client_generation.bal index 8fb8e44f8..859a6d279 100644 --- a/openapi-cli/src/test/resources/expected_gen/licenses/utils_for_client_generation.bal +++ b/openapi-cli/src/test/resources/expected_gen/licenses/utils_for_client_generation.bal @@ -1,6 +1,7 @@ // AUTO-GENERATED FILE. DO NOT MODIFY. // This file is auto-generated by the Ballerina OpenAPI tool. +import ballerina/http; import ballerina/url; type SimpleBasicType string|boolean|int|float|decimal; @@ -170,12 +171,13 @@ isolated function getEncodedUri(anydata value) returns string { # + encodingMap - Details on serialization mechanism # + return - Returns generated Path or error at failure of client initialization isolated function getPathForQueryParam(map queryParam, map encodingMap = {}) returns string|error { + map queriesMap = http:getQueryMap(queryParam); string[] param = []; - if queryParam.length() > 0 { + if queriesMap.length() > 0 { param.push("?"); - foreach var [key, value] in queryParam.entries() { + foreach var [key, value] in queriesMap.entries() { if value is () { - _ = queryParam.remove(key); + _ = queriesMap.remove(key); continue; } Encoding encodingData = encodingMap.hasKey(key) ? encodingMap.get(key) : defaultEncoding; diff --git a/openapi-cli/src/test/resources/expected_gen/licenses/utils_for_with_user_given_license.bal b/openapi-cli/src/test/resources/expected_gen/licenses/utils_for_with_user_given_license.bal index 22d3c7426..5c1ddc5c0 100644 --- a/openapi-cli/src/test/resources/expected_gen/licenses/utils_for_with_user_given_license.bal +++ b/openapi-cli/src/test/resources/expected_gen/licenses/utils_for_with_user_given_license.bal @@ -1,5 +1,6 @@ // Copyright (c) 2023 All Rights Reserved. +import ballerina/http; import ballerina/url; type SimpleBasicType string|boolean|int|float|decimal; @@ -169,12 +170,13 @@ isolated function getEncodedUri(anydata value) returns string { # + encodingMap - Details on serialization mechanism # + return - Returns generated Path or error at failure of client initialization isolated function getPathForQueryParam(map queryParam, map encodingMap = {}) returns string|error { + map queriesMap = http:getQueryMap(queryParam); string[] param = []; - if queryParam.length() > 0 { + if queriesMap.length() > 0 { param.push("?"); - foreach var [key, value] in queryParam.entries() { + foreach var [key, value] in queriesMap.entries() { if value is () { - _ = queryParam.remove(key); + _ = queriesMap.remove(key); continue; } Encoding encodingData = encodingMap.hasKey(key) ? encodingMap.get(key) : defaultEncoding; diff --git a/openapi-cli/src/test/resources/expected_gen/petstore_catch_all_path_client.bal b/openapi-cli/src/test/resources/expected_gen/petstore_catch_all_path_client.bal index 9111a7ccf..496531bbf 100644 --- a/openapi-cli/src/test/resources/expected_gen/petstore_catch_all_path_client.bal +++ b/openapi-cli/src/test/resources/expected_gen/petstore_catch_all_path_client.bal @@ -53,7 +53,7 @@ public isolated client class Client { headerValues["api_key"] = self.apiKeyConfig?.api_key; } resourcePath = resourcePath + check getPathForQueryParam(queries); - map httpHeaders = getMapForHeaders(headerValues); + map httpHeaders = http:getHeaderMap(headerValues); return self.clientEp->get(resourcePath, httpHeaders); } diff --git a/openapi-cli/src/test/resources/expected_gen/petstore_client_swagger.bal b/openapi-cli/src/test/resources/expected_gen/petstore_client_swagger.bal index 94a4dd4bb..a48a1b963 100644 --- a/openapi-cli/src/test/resources/expected_gen/petstore_client_swagger.bal +++ b/openapi-cli/src/test/resources/expected_gen/petstore_client_swagger.bal @@ -110,7 +110,7 @@ public isolated client class Client { # + return - Invalid ID supplied remote isolated function deletePet(int petId, DeletePetHeaders headers = {}) returns http:Response|error { string resourcePath = string `/pet/${getEncodedUri(petId)}`; - map httpHeaders = getMapForHeaders(headers); + map httpHeaders = http:getHeaderMap(headers); return self.clientEp->delete(resourcePath, headers = httpHeaders); } @@ -161,7 +161,7 @@ public isolated client class Client { if self.apiKeyConfig is ApiKeysConfig { headerValues["api_key"] = self.apiKeyConfig?.api_key; } - map httpHeaders = getMapForHeaders(headerValues); + map httpHeaders = http:getHeaderMap(headerValues); return self.clientEp->get(resourcePath, httpHeaders); } @@ -186,7 +186,7 @@ public isolated client class Client { if self.apiKeyConfig is ApiKeysConfig { headerValues["api_key"] = self.apiKeyConfig?.api_key; } - map httpHeaders = getMapForHeaders(headerValues); + map httpHeaders = http:getHeaderMap(headerValues); return self.clientEp->get(resourcePath, httpHeaders); } diff --git a/openapi-cli/src/test/resources/expected_gen/sanitize_array_member.bal b/openapi-cli/src/test/resources/expected_gen/sanitize_array_member.bal index 7c972f5a5..06ddbfb35 100644 --- a/openapi-cli/src/test/resources/expected_gen/sanitize_array_member.bal +++ b/openapi-cli/src/test/resources/expected_gen/sanitize_array_member.bal @@ -47,7 +47,7 @@ public isolated client class Client { resource isolated function get albums(GetAlbumsHeaders headers = {}, *GetAlbumsQueries queries) returns Album[]|error { string resourcePath = string `/albums`; resourcePath = resourcePath + check getPathForQueryParam(queries); - map httpHeaders = getMapForHeaders(headers); + map httpHeaders = http:getHeaderMap(headers); return self.clientEp->get(resourcePath, httpHeaders); } } @@ -219,12 +219,13 @@ isolated function getEncodedUri(anydata value) returns string { # + encodingMap - Details on serialization mechanism # + return - Returns generated Path or error at failure of client initialization isolated function getPathForQueryParam(map queryParam, map encodingMap = {}) returns string|error { + map queriesMap = http:getQueryMap(queryParam); string[] param = []; - if queryParam.length() > 0 { + if queriesMap.length() > 0 { param.push("?"); - foreach var [key, value] in queryParam.entries() { + foreach var [key, value] in queriesMap.entries() { if value is () { - _ = queryParam.remove(key); + _ = queriesMap.remove(key); continue; } Encoding encodingData = encodingMap.hasKey(key) ? encodingMap.get(key) : defaultEncoding; @@ -249,23 +250,6 @@ isolated function getPathForQueryParam(map queryParam, map en return restOfPath; } -# Generate header map for given header values. -# -# + headerParam - Headers map -# + return - Returns generated map or error at failure of client initialization -isolated function getMapForHeaders(map headerParam) returns map { - map headerMap = {}; - foreach var [key, value] in headerParam.entries() { - if value is SimpleBasicType[] { - headerMap[key] = from SimpleBasicType data in value - select data.toString(); - } else { - headerMap[key] = value.toString(); - } - } - return headerMap; -} - # Provides settings related to HTTP/1.x protocol. public type ClientHttp1Settings record {| # Specifies whether to reuse a connection for multiple requests diff --git a/openapi-cli/src/test/resources/expected_gen/type_name_with_mixed_case.bal b/openapi-cli/src/test/resources/expected_gen/type_name_with_mixed_case.bal index a54b92a74..f57c38b38 100644 --- a/openapi-cli/src/test/resources/expected_gen/type_name_with_mixed_case.bal +++ b/openapi-cli/src/test/resources/expected_gen/type_name_with_mixed_case.bal @@ -47,7 +47,7 @@ public isolated client class Client { resource isolated function get albums(GetAlbumsHeaders headers = {}, *GetAlbumsQueries queries) returns AlbumNewOne[]|error { string resourcePath = string `/albums`; resourcePath = resourcePath + check getPathForQueryParam(queries); - map httpHeaders = getMapForHeaders(headers); + map httpHeaders = http:getHeaderMap(headers); return self.clientEp->get(resourcePath, httpHeaders); } } @@ -219,12 +219,13 @@ isolated function getEncodedUri(anydata value) returns string { # + encodingMap - Details on serialization mechanism # + return - Returns generated Path or error at failure of client initialization isolated function getPathForQueryParam(map queryParam, map encodingMap = {}) returns string|error { + map queriesMap = http:getQueryMap(queryParam); string[] param = []; - if queryParam.length() > 0 { + if queriesMap.length() > 0 { param.push("?"); - foreach var [key, value] in queryParam.entries() { + foreach var [key, value] in queriesMap.entries() { if value is () { - _ = queryParam.remove(key); + _ = queriesMap.remove(key); continue; } Encoding encodingData = encodingMap.hasKey(key) ? encodingMap.get(key) : defaultEncoding; @@ -249,23 +250,6 @@ isolated function getPathForQueryParam(map queryParam, map en return restOfPath; } -# Generate header map for given header values. -# -# + headerParam - Headers map -# + return - Returns generated map or error at failure of client initialization -isolated function getMapForHeaders(map headerParam) returns map { - map headerMap = {}; - foreach var [key, value] in headerParam.entries() { - if value is SimpleBasicType[] { - headerMap[key] = from SimpleBasicType data in value - select data.toString(); - } else { - headerMap[key] = value.toString(); - } - } - return headerMap; -} - public type AlbumNewOne record {| # Album artist string artist; diff --git a/openapi-cli/src/test/resources/expected_gen/utils.bal b/openapi-cli/src/test/resources/expected_gen/utils.bal index 90ff1cbac..761caf12f 100644 --- a/openapi-cli/src/test/resources/expected_gen/utils.bal +++ b/openapi-cli/src/test/resources/expected_gen/utils.bal @@ -1,3 +1,4 @@ +import ballerina/http; import ballerina/url; type SimpleBasicType string|boolean|int|float|decimal; @@ -170,12 +171,13 @@ isolated function getEncodedUri(anydata value) returns string { # + encodingMap - Details on serialization mechanism # + return - Returns generated Path or error at failure of client initialization isolated function getPathForQueryParam(map queryParam, map encodingMap = {}) returns string|error { + map queriesMap = http:getQueryMap(queryParam); string[] param = []; - if queryParam.length() > 0 { + if queriesMap.length() > 0 { param.push("?"); - foreach var [key, value] in queryParam.entries() { + foreach var [key, value] in queriesMap.entries() { if value is () { - _ = queryParam.remove(key); + _ = queriesMap.remove(key); continue; } Encoding encodingData = encodingMap.hasKey(key) ? encodingMap.get(key) : defaultEncoding; diff --git a/openapi-cli/src/test/resources/generators/client/ballerina/combination_of_apikey_and_http_oauth.bal b/openapi-cli/src/test/resources/generators/client/ballerina/combination_of_apikey_and_http_oauth.bal index 254cbf75e..49bb03bdf 100644 --- a/openapi-cli/src/test/resources/generators/client/ballerina/combination_of_apikey_and_http_oauth.bal +++ b/openapi-cli/src/test/resources/generators/client/ballerina/combination_of_apikey_and_http_oauth.bal @@ -56,7 +56,7 @@ public isolated client class Client { queryParam["api-key-2"] = self.apiKeyConfig?.api\-key\-2; } resourcePath = resourcePath + check getPathForQueryParam(queryParam); - map httpHeaders = getMapForHeaders(headerValues); + map httpHeaders = http:getHeaderMap(headerValues); return self.clientEp->delete(resourcePath, headers = httpHeaders); } @@ -73,7 +73,7 @@ public isolated client class Client { queryParam["api-key-2"] = self.apiKeyConfig?.api\-key\-2; } resourcePath = resourcePath + check getPathForQueryParam(queryParam); - map httpHeaders = getMapForHeaders(headerValues); + map httpHeaders = http:getHeaderMap(headerValues); return self.clientEp->delete(resourcePath, headers = httpHeaders); } @@ -91,7 +91,7 @@ public isolated client class Client { queryParam["api-key-2"] = self.apiKeyConfig?.api\-key\-2; } resourcePath = resourcePath + check getPathForQueryParam(queryParam); - map httpHeaders = getMapForHeaders(headerValues); + map httpHeaders = http:getHeaderMap(headerValues); return self.clientEp->get(resourcePath, httpHeaders); } @@ -108,7 +108,7 @@ public isolated client class Client { queryParam["api-key-2"] = self.apiKeyConfig?.api\-key\-2; } resourcePath = resourcePath + check getPathForQueryParam(queryParam); - map httpHeaders = getMapForHeaders(headerValues); + map httpHeaders = http:getHeaderMap(headerValues); http:Request request = new; return self.clientEp->post(resourcePath, request, httpHeaders); } diff --git a/openapi-cli/src/test/resources/generators/client/ballerina/delete_with_header.bal b/openapi-cli/src/test/resources/generators/client/ballerina/delete_with_header.bal index be2fd36a8..deb435421 100644 --- a/openapi-cli/src/test/resources/generators/client/ballerina/delete_with_header.bal +++ b/openapi-cli/src/test/resources/generators/client/ballerina/delete_with_header.bal @@ -41,7 +41,7 @@ public isolated client class Client { # + return - Status OK remote isolated function deleteHeader(DeleteHeaderHeaders headers) returns error? { string resourcePath = string `/header`; - map httpHeaders = getMapForHeaders(headers); + map httpHeaders = http:getHeaderMap(headers); return self.clientEp->delete(resourcePath, headers = httpHeaders); } @@ -51,7 +51,7 @@ public isolated client class Client { # + return - Status OK remote isolated function deleteHeaderRequestBody(DeleteHeaderRequestBodyHeaders headers, json payload) returns error? { string resourcePath = string `/header-with-request-body`; - map httpHeaders = getMapForHeaders(headers); + map httpHeaders = http:getHeaderMap(headers); http:Request request = new; request.setPayload(payload, "application/json"); return self.clientEp->delete(resourcePath, request, httpHeaders); diff --git a/openapi-cli/src/test/resources/generators/client/ballerina/header_integer_signed32.bal b/openapi-cli/src/test/resources/generators/client/ballerina/header_integer_signed32.bal index d3a28b43a..12c051437 100644 --- a/openapi-cli/src/test/resources/generators/client/ballerina/header_integer_signed32.bal +++ b/openapi-cli/src/test/resources/generators/client/ballerina/header_integer_signed32.bal @@ -46,7 +46,7 @@ public isolated client class Client { string resourcePath = string `/pets`; map headerValues = {...headers}; headerValues["X-API-KEY"] = self.apiKeyConfig.X\-API\-KEY; - map httpHeaders = getMapForHeaders(headerValues); + map httpHeaders = http:getHeaderMap(headerValues); return self.clientEp->get(resourcePath, httpHeaders); } } diff --git a/openapi-cli/src/test/resources/generators/client/ballerina/header_optional.bal b/openapi-cli/src/test/resources/generators/client/ballerina/header_optional.bal index eac5ae07b..2e9e349f7 100644 --- a/openapi-cli/src/test/resources/generators/client/ballerina/header_optional.bal +++ b/openapi-cli/src/test/resources/generators/client/ballerina/header_optional.bal @@ -50,7 +50,7 @@ public isolated client class Client { map queryParam = {...queries}; queryParam["appid"] = self.apiKeyConfig.appid; resourcePath = resourcePath + check getPathForQueryParam(queryParam); - map httpHeaders = getMapForHeaders(headers); + map httpHeaders = http:getHeaderMap(headers); return self.clientEp->get(resourcePath, httpHeaders); } } diff --git a/openapi-cli/src/test/resources/generators/client/ballerina/header_param_with_default_value.bal b/openapi-cli/src/test/resources/generators/client/ballerina/header_param_with_default_value.bal index 1f58bdb45..579570932 100644 --- a/openapi-cli/src/test/resources/generators/client/ballerina/header_param_with_default_value.bal +++ b/openapi-cli/src/test/resources/generators/client/ballerina/header_param_with_default_value.bal @@ -59,7 +59,7 @@ public isolated client class Client { map queryParam = {...queries}; queryParam["appid"] = self.apiKeyConfig.appid; resourcePath = resourcePath + check getPathForQueryParam(queryParam); - map httpHeaders = getMapForHeaders(headers); + map httpHeaders = http:getHeaderMap(headers); return self.clientEp->get(resourcePath, httpHeaders); } } diff --git a/openapi-cli/src/test/resources/generators/client/ballerina/header_parameter.bal b/openapi-cli/src/test/resources/generators/client/ballerina/header_parameter.bal index d3a28b43a..12c051437 100644 --- a/openapi-cli/src/test/resources/generators/client/ballerina/header_parameter.bal +++ b/openapi-cli/src/test/resources/generators/client/ballerina/header_parameter.bal @@ -46,7 +46,7 @@ public isolated client class Client { string resourcePath = string `/pets`; map headerValues = {...headers}; headerValues["X-API-KEY"] = self.apiKeyConfig.X\-API\-KEY; - map httpHeaders = getMapForHeaders(headerValues); + map httpHeaders = http:getHeaderMap(headerValues); return self.clientEp->get(resourcePath, httpHeaders); } } diff --git a/openapi-cli/src/test/resources/generators/client/ballerina/header_without_parameter.bal b/openapi-cli/src/test/resources/generators/client/ballerina/header_without_parameter.bal index 7706036fb..738be1f6c 100644 --- a/openapi-cli/src/test/resources/generators/client/ballerina/header_without_parameter.bal +++ b/openapi-cli/src/test/resources/generators/client/ballerina/header_without_parameter.bal @@ -46,7 +46,7 @@ public isolated client class Client { string resourcePath = string `/pets`; map headerValues = {...headers}; headerValues["X-API-KEY"] = self.apiKeyConfig.X\-API\-KEY; - map httpHeaders = getMapForHeaders(headerValues); + map httpHeaders = http:getHeaderMap(headerValues); return self.clientEp->get(resourcePath, httpHeaders); } } diff --git a/openapi-cli/src/test/resources/generators/client/ballerina/parameters_with_enum.bal b/openapi-cli/src/test/resources/generators/client/ballerina/parameters_with_enum.bal index d9c6b1e80..df42b642e 100644 --- a/openapi-cli/src/test/resources/generators/client/ballerina/parameters_with_enum.bal +++ b/openapi-cli/src/test/resources/generators/client/ballerina/parameters_with_enum.bal @@ -55,7 +55,7 @@ public isolated client class Client { string resourcePath = string `/users/meetings/${getEncodedUri(group)}`; map queryParamEncoding = {"status": {style: FORM, explode: true}}; resourcePath = resourcePath + check getPathForQueryParam(queries, queryParamEncoding); - map httpHeaders = getMapForHeaders(headers); + map httpHeaders = http:getHeaderMap(headers); return self.clientEp->get(resourcePath, httpHeaders); } } diff --git a/openapi-cli/src/test/resources/generators/client/ballerina/parameters_with_nullable_enums.bal b/openapi-cli/src/test/resources/generators/client/ballerina/parameters_with_nullable_enums.bal index e8d688387..67f43047e 100644 --- a/openapi-cli/src/test/resources/generators/client/ballerina/parameters_with_nullable_enums.bal +++ b/openapi-cli/src/test/resources/generators/client/ballerina/parameters_with_nullable_enums.bal @@ -54,7 +54,7 @@ public isolated client class Client { string resourcePath = string `/users/meetings`; map queryParamEncoding = {"status": {style: FORM, explode: true}}; resourcePath = resourcePath + check getPathForQueryParam(queries, queryParamEncoding); - map httpHeaders = getMapForHeaders(headers); + map httpHeaders = http:getHeaderMap(headers); return self.clientEp->get(resourcePath, httpHeaders); } } diff --git a/openapi-cli/src/test/resources/generators/client/ballerina/parameters_with_nullable_enums_resource.bal b/openapi-cli/src/test/resources/generators/client/ballerina/parameters_with_nullable_enums_resource.bal index 762ab98bf..017b8ceb8 100644 --- a/openapi-cli/src/test/resources/generators/client/ballerina/parameters_with_nullable_enums_resource.bal +++ b/openapi-cli/src/test/resources/generators/client/ballerina/parameters_with_nullable_enums_resource.bal @@ -54,7 +54,7 @@ public isolated client class Client { string resourcePath = string `/users/meetings`; map queryParamEncoding = {"status": {style: FORM, explode: true}}; resourcePath = resourcePath + check getPathForQueryParam(queries, queryParamEncoding); - map httpHeaders = getMapForHeaders(headers); + map httpHeaders = http:getHeaderMap(headers); return self.clientEp->get(resourcePath, httpHeaders); } } diff --git a/openapi-cli/src/test/resources/generators/client/ballerina/paramters_with_enum_resource.bal b/openapi-cli/src/test/resources/generators/client/ballerina/paramters_with_enum_resource.bal index 8e20de193..1fd3a8cdc 100644 --- a/openapi-cli/src/test/resources/generators/client/ballerina/paramters_with_enum_resource.bal +++ b/openapi-cli/src/test/resources/generators/client/ballerina/paramters_with_enum_resource.bal @@ -55,7 +55,7 @@ public isolated client class Client { string resourcePath = string `/users/meetings/${getEncodedUri(group)}`; map queryParamEncoding = {"status": {style: FORM, explode: true}}; resourcePath = resourcePath + check getPathForQueryParam(queries, queryParamEncoding); - map httpHeaders = getMapForHeaders(headers); + map httpHeaders = http:getHeaderMap(headers); return self.clientEp->get(resourcePath, httpHeaders); } } diff --git a/openapi-cli/src/test/resources/generators/client/file_provider/ballerina/api2pdf.bal b/openapi-cli/src/test/resources/generators/client/file_provider/ballerina/api2pdf.bal index 7e2a0bc0f..d00cd24ed 100644 --- a/openapi-cli/src/test/resources/generators/client/file_provider/ballerina/api2pdf.bal +++ b/openapi-cli/src/test/resources/generators/client/file_provider/ballerina/api2pdf.bal @@ -48,7 +48,7 @@ public isolated client class Client { string resourcePath = string `/chrome/html`; map headerValues = {...headers}; headerValues["Authorization"] = self.apiKeyConfig.Authorization; - map httpHeaders = getMapForHeaders(headerValues); + map httpHeaders = http:getHeaderMap(headerValues); http:Request request = new; json jsonBody = payload.toJson(); request.setPayload(jsonBody, "application/json"); @@ -77,7 +77,7 @@ public isolated client class Client { string resourcePath = string `/chrome/url`; map headerValues = {...headers}; headerValues["Authorization"] = self.apiKeyConfig.Authorization; - map httpHeaders = getMapForHeaders(headerValues); + map httpHeaders = http:getHeaderMap(headerValues); http:Request request = new; json jsonBody = payload.toJson(); request.setPayload(jsonBody, "application/json"); @@ -93,7 +93,7 @@ public isolated client class Client { string resourcePath = string `/libreoffice/convert`; map headerValues = {...headers}; headerValues["Authorization"] = self.apiKeyConfig.Authorization; - map httpHeaders = getMapForHeaders(headerValues); + map httpHeaders = http:getHeaderMap(headerValues); http:Request request = new; json jsonBody = payload.toJson(); request.setPayload(jsonBody, "application/json"); @@ -109,7 +109,7 @@ public isolated client class Client { string resourcePath = string `/merge`; map headerValues = {...headers}; headerValues["Authorization"] = self.apiKeyConfig.Authorization; - map httpHeaders = getMapForHeaders(headerValues); + map httpHeaders = http:getHeaderMap(headerValues); http:Request request = new; json jsonBody = payload.toJson(); request.setPayload(jsonBody, "application/json"); @@ -125,7 +125,7 @@ public isolated client class Client { string resourcePath = string `/wkhtmltopdf/html`; map headerValues = {...headers}; headerValues["Authorization"] = self.apiKeyConfig.Authorization; - map httpHeaders = getMapForHeaders(headerValues); + map httpHeaders = http:getHeaderMap(headerValues); http:Request request = new; json jsonBody = payload.toJson(); request.setPayload(jsonBody, "application/json"); @@ -154,7 +154,7 @@ public isolated client class Client { string resourcePath = string `/wkhtmltopdf/url`; map headerValues = {...headers}; headerValues["Authorization"] = self.apiKeyConfig.Authorization; - map httpHeaders = getMapForHeaders(headerValues); + map httpHeaders = http:getHeaderMap(headerValues); http:Request request = new; json jsonBody = payload.toJson(); request.setPayload(jsonBody, "application/json"); diff --git a/openapi-cli/src/test/resources/generators/client/file_provider/ballerina/header_with_enum.bal b/openapi-cli/src/test/resources/generators/client/file_provider/ballerina/header_with_enum.bal index 37c63dcff..e44c55f22 100644 --- a/openapi-cli/src/test/resources/generators/client/file_provider/ballerina/header_with_enum.bal +++ b/openapi-cli/src/test/resources/generators/client/file_provider/ballerina/header_with_enum.bal @@ -42,7 +42,7 @@ public isolated client class Client { # + return - successful operation remote isolated function getInventory(GetInventoryHeaders headers = {}) returns record {|int:Signed32...;|}|error { string resourcePath = string `/store/inventory`; - map httpHeaders = getMapForHeaders(headers); + map httpHeaders = http:getHeaderMap(headers); return self.clientEp->get(resourcePath, httpHeaders); } } diff --git a/openapi-cli/src/test/resources/generators/client/file_provider/ballerina/multiline_param_comment.bal b/openapi-cli/src/test/resources/generators/client/file_provider/ballerina/multiline_param_comment.bal index f76cedc62..1ac415bc4 100644 --- a/openapi-cli/src/test/resources/generators/client/file_provider/ballerina/multiline_param_comment.bal +++ b/openapi-cli/src/test/resources/generators/client/file_provider/ballerina/multiline_param_comment.bal @@ -51,7 +51,7 @@ public isolated client class Client { resourcePath = resourcePath + check getPathForQueryParam(queries); map headerValues = {...headers}; headerValues["api-key"] = self.apiKeyConfig.api\-key; - map httpHeaders = getMapForHeaders(headerValues); + map httpHeaders = http:getHeaderMap(headerValues); return self.clientEp->get(resourcePath, httpHeaders); } } diff --git a/openapi-cli/src/test/resources/generators/client/resource/ballerina/header.bal b/openapi-cli/src/test/resources/generators/client/resource/ballerina/header.bal index 9422e2f5c..3e51cfb4b 100644 --- a/openapi-cli/src/test/resources/generators/client/resource/ballerina/header.bal +++ b/openapi-cli/src/test/resources/generators/client/resource/ballerina/header.bal @@ -51,7 +51,7 @@ public isolated client class Client { map queryParam = {...queries}; queryParam["appid"] = self.apiKeyConfig.appid; resourcePath = resourcePath + check getPathForQueryParam(queryParam); - map httpHeaders = getMapForHeaders(headers); + map httpHeaders = http:getHeaderMap(headers); return self.clientEp->get(resourcePath, httpHeaders); } @@ -64,7 +64,7 @@ public isolated client class Client { map queryParam = {}; queryParam["appid"] = self.apiKeyConfig.appid; resourcePath = resourcePath + check getPathForQueryParam(queryParam); - map httpHeaders = getMapForHeaders(headers); + map httpHeaders = http:getHeaderMap(headers); return self.clientEp->get(resourcePath, httpHeaders); } } diff --git a/openapi-integration-tests/src/test/resources/client/expected/project-09/client.bal b/openapi-integration-tests/src/test/resources/client/expected/project-09/client.bal index e078597ca..82b04002f 100644 --- a/openapi-integration-tests/src/test/resources/client/expected/project-09/client.bal +++ b/openapi-integration-tests/src/test/resources/client/expected/project-09/client.bal @@ -63,7 +63,7 @@ public isolated client class Client { headerValues["api-key"] = self.apiKeyConfig?.api\-key; } resourcePath = resourcePath + check getPathForQueryParam(queries); - map httpHeaders = getMapForHeaders(headerValues); + map httpHeaders = http:getHeaderMap(headerValues); http:Request request = new; json jsonBody = payload.toJson(); request.setPayload(jsonBody, "application/json"); @@ -83,7 +83,7 @@ public isolated client class Client { headerValues["api-key"] = self.apiKeyConfig?.api\-key; } resourcePath = resourcePath + check getPathForQueryParam(queries); - map httpHeaders = getMapForHeaders(headerValues); + map httpHeaders = http:getHeaderMap(headerValues); http:Request request = new; json jsonBody = payload.toJson(); request.setPayload(jsonBody, "application/json"); diff --git a/openapi-integration-tests/src/test/resources/client/expected/project-09/utils.bal b/openapi-integration-tests/src/test/resources/client/expected/project-09/utils.bal index 1b492b2aa..859a6d279 100644 --- a/openapi-integration-tests/src/test/resources/client/expected/project-09/utils.bal +++ b/openapi-integration-tests/src/test/resources/client/expected/project-09/utils.bal @@ -1,6 +1,7 @@ // AUTO-GENERATED FILE. DO NOT MODIFY. // This file is auto-generated by the Ballerina OpenAPI tool. +import ballerina/http; import ballerina/url; type SimpleBasicType string|boolean|int|float|decimal; @@ -170,12 +171,13 @@ isolated function getEncodedUri(anydata value) returns string { # + encodingMap - Details on serialization mechanism # + return - Returns generated Path or error at failure of client initialization isolated function getPathForQueryParam(map queryParam, map encodingMap = {}) returns string|error { + map queriesMap = http:getQueryMap(queryParam); string[] param = []; - if queryParam.length() > 0 { + if queriesMap.length() > 0 { param.push("?"); - foreach var [key, value] in queryParam.entries() { + foreach var [key, value] in queriesMap.entries() { if value is () { - _ = queryParam.remove(key); + _ = queriesMap.remove(key); continue; } Encoding encodingData = encodingMap.hasKey(key) ? encodingMap.get(key) : defaultEncoding; @@ -199,20 +201,3 @@ isolated function getPathForQueryParam(map queryParam, map en string restOfPath = string:'join("", ...param); return restOfPath; } - -# Generate header map for given header values. -# -# + headerParam - Headers map -# + return - Returns generated map or error at failure of client initialization -isolated function getMapForHeaders(map headerParam) returns map { - map headerMap = {}; - foreach var [key, value] in headerParam.entries() { - if value is SimpleBasicType[] { - headerMap[key] = from SimpleBasicType data in value - select data.toString(); - } else { - headerMap[key] = value.toString(); - } - } - return headerMap; -} diff --git a/openapi-integration-tests/src/test/resources/client/project-expected/utils.bal b/openapi-integration-tests/src/test/resources/client/project-expected/utils.bal index 8fb8e44f8..859a6d279 100644 --- a/openapi-integration-tests/src/test/resources/client/project-expected/utils.bal +++ b/openapi-integration-tests/src/test/resources/client/project-expected/utils.bal @@ -1,6 +1,7 @@ // AUTO-GENERATED FILE. DO NOT MODIFY. // This file is auto-generated by the Ballerina OpenAPI tool. +import ballerina/http; import ballerina/url; type SimpleBasicType string|boolean|int|float|decimal; @@ -170,12 +171,13 @@ isolated function getEncodedUri(anydata value) returns string { # + encodingMap - Details on serialization mechanism # + return - Returns generated Path or error at failure of client initialization isolated function getPathForQueryParam(map queryParam, map encodingMap = {}) returns string|error { + map queriesMap = http:getQueryMap(queryParam); string[] param = []; - if queryParam.length() > 0 { + if queriesMap.length() > 0 { param.push("?"); - foreach var [key, value] in queryParam.entries() { + foreach var [key, value] in queriesMap.entries() { if value is () { - _ = queryParam.remove(key); + _ = queriesMap.remove(key); continue; } Encoding encodingData = encodingMap.hasKey(key) ? encodingMap.get(key) : defaultEncoding; diff --git a/openapi-integration-tests/src/test/resources/client/project-expected/utils_all.bal b/openapi-integration-tests/src/test/resources/client/project-expected/utils_all.bal index 461d33b75..e470e3e51 100644 --- a/openapi-integration-tests/src/test/resources/client/project-expected/utils_all.bal +++ b/openapi-integration-tests/src/test/resources/client/project-expected/utils_all.bal @@ -1,6 +1,7 @@ // AUTO-GENERATED FILE. // This file is auto-generated by the Ballerina OpenAPI tool. +import ballerina/http; import ballerina/url; type SimpleBasicType string|boolean|int|float|decimal; @@ -170,12 +171,13 @@ isolated function getEncodedUri(anydata value) returns string { # + encodingMap - Details on serialization mechanism # + return - Returns generated Path or error at failure of client initialization isolated function getPathForQueryParam(map queryParam, map encodingMap = {}) returns string|error { + map queriesMap = http:getQueryMap(queryParam); string[] param = []; - if queryParam.length() > 0 { + if queriesMap.length() > 0 { param.push("?"); - foreach var [key, value] in queryParam.entries() { + foreach var [key, value] in queriesMap.entries() { if value is () { - _ = queryParam.remove(key); + _ = queriesMap.remove(key); continue; } Encoding encodingData = encodingMap.hasKey(key) ? encodingMap.get(key) : defaultEncoding; diff --git a/openapi-integration-tests/src/test/resources/client/project-expected/utils_all_with_default.bal b/openapi-integration-tests/src/test/resources/client/project-expected/utils_all_with_default.bal index da3c72152..5b2e4d72e 100644 --- a/openapi-integration-tests/src/test/resources/client/project-expected/utils_all_with_default.bal +++ b/openapi-integration-tests/src/test/resources/client/project-expected/utils_all_with_default.bal @@ -171,12 +171,13 @@ isolated function getEncodedUri(anydata value) returns string { # + encodingMap - Details on serialization mechanism # + return - Returns generated Path or error at failure of client initialization isolated function getPathForQueryParam(map queryParam, map encodingMap = {}) returns string|error { + map queriesMap = http:getQueryMap(queryParam); string[] param = []; - if queryParam.length() > 0 { + if queriesMap.length() > 0 { param.push("?"); - foreach var [key, value] in queryParam.entries() { + foreach var [key, value] in queriesMap.entries() { if value is () { - _ = queryParam.remove(key); + _ = queriesMap.remove(key); continue; } Encoding encodingData = encodingMap.hasKey(key) ? encodingMap.get(key) : defaultEncoding; diff --git a/openapi-integration-tests/src/test/resources/client/project-expected/utils_with_default.bal b/openapi-integration-tests/src/test/resources/client/project-expected/utils_with_default.bal index efac0ccab..bc5ba3785 100644 --- a/openapi-integration-tests/src/test/resources/client/project-expected/utils_with_default.bal +++ b/openapi-integration-tests/src/test/resources/client/project-expected/utils_with_default.bal @@ -171,12 +171,13 @@ isolated function getEncodedUri(anydata value) returns string { # + encodingMap - Details on serialization mechanism # + return - Returns generated Path or error at failure of client initialization isolated function getPathForQueryParam(map queryParam, map encodingMap = {}) returns string|error { + map queriesMap = http:getQueryMap(queryParam); string[] param = []; - if queryParam.length() > 0 { + if queriesMap.length() > 0 { param.push("?"); - foreach var [key, value] in queryParam.entries() { + foreach var [key, value] in queriesMap.entries() { if value is () { - _ = queryParam.remove(key); + _ = queriesMap.remove(key); continue; } Encoding encodingData = encodingMap.hasKey(key) ? encodingMap.get(key) : defaultEncoding;