diff --git a/gradle.properties b/gradle.properties index 92406a7ab..b2bc0ecc9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -49,7 +49,7 @@ stdlibJwtVersion=2.13.0 stdlibOAuth2Version=2.12.0 # Stdlib Level 05 -stdlibHttpVersion=2.12.1-20240918-130700-9906dbe +stdlibHttpVersion=2.12.1-20240922-195800-82c5e76 # Stdlib Level 06 stdlibGrpcVersion=1.12.0 diff --git a/openapi-core/src/main/java/io/ballerina/openapi/core/generators/client/BallerinaUtilGenerator.java b/openapi-core/src/main/java/io/ballerina/openapi/core/generators/client/BallerinaUtilGenerator.java index 44df9074a..0019a632b 100644 --- a/openapi-core/src/main/java/io/ballerina/openapi/core/generators/client/BallerinaUtilGenerator.java +++ b/openapi-core/src/main/java/io/ballerina/openapi/core/generators/client/BallerinaUtilGenerator.java @@ -121,7 +121,6 @@ */ public class BallerinaUtilGenerator { - private boolean headersFound = false; private boolean pathParametersFound = false; private boolean queryParamsFound = false; private boolean requestBodyEncodingFound = false; @@ -136,7 +135,6 @@ public class BallerinaUtilGenerator { private static final String GET_ENCODED_URI = "getEncodedUri"; private static final String GET_ORIGINAL_KEY = "getOriginalKey"; private static final String GET_PATH_FOR_QUERY_PARAM = "getPathForQueryParam"; - private static final String GET_MAP_FOR_HEADERS = "getMapForHeaders"; private static final String GET_SERIALIZED_RECORD_ARRAY = "getSerializedRecordArray"; private static final String CREATE_MULTIPART_BODY_PARTS = "createBodyParts"; private static final String GET_VALIDATED_RESPONSE_FOR_DEFAULT_MAPPING = "getValidatedResponseForDefaultMapping"; @@ -151,16 +149,6 @@ public void setQueryParamsFound(boolean flag) { this.queryParamsFound = flag; } - /** - * Set `headersFound` flag to `true` when at least one header found. - * - * @param flag Function will be called only in the occasions where flag needs to be set to `true` - */ - public void setHeadersFound(boolean flag) { - - this.headersFound = flag; - } - /** * Set `pathParametersFound` flag to `true` when at least one path parameter found. * @@ -260,9 +248,6 @@ private Set getFunctionNameList() { GET_SERIALIZED_RECORD_ARRAY )); } - if (headersFound) { - functionNameList.add(GET_MAP_FOR_HEADERS); - } if (pathParametersFound) { functionNameList.add(GET_ENCODED_URI); } @@ -288,7 +273,7 @@ private List generateImports(Set functionNameList ImportDeclarationNode importMime = GeneratorUtils.getImportDeclarationNode(BALLERINA, MIME); imports.add(importMime); } - if (defaultStatusCodeResponseBindingFound) { + if (defaultStatusCodeResponseBindingFound || queryParamsFound) { ImportDeclarationNode importForHttp = GeneratorUtils.getImportDeclarationNode(BALLERINA, HTTP); imports.add(importForHttp); } @@ -301,7 +286,7 @@ private List generateImports(Set functionNameList * @param memberDeclarationNodes {@link ModuleMemberDeclarationNode} */ private void getUtilTypeDeclarationNodes(List memberDeclarationNodes) { - if (requestBodyEncodingFound || queryParamsFound || headersFound || requestBodyMultipartFormDatafound) { + if (requestBodyEncodingFound || queryParamsFound || requestBodyMultipartFormDatafound) { memberDeclarationNodes.add(getSimpleBasicTypeDefinitionNode()); } if (requestBodyEncodingFound || queryParamsFound || requestBodyMultipartFormDatafound) { diff --git a/openapi-core/src/main/java/io/ballerina/openapi/core/generators/client/FunctionBodyGeneratorImp.java b/openapi-core/src/main/java/io/ballerina/openapi/core/generators/client/FunctionBodyGeneratorImp.java index 4030803e2..53ac6b781 100644 --- a/openapi-core/src/main/java/io/ballerina/openapi/core/generators/client/FunctionBodyGeneratorImp.java +++ b/openapi-core/src/main/java/io/ballerina/openapi/core/generators/client/FunctionBodyGeneratorImp.java @@ -128,7 +128,7 @@ public class FunctionBodyGeneratorImp implements FunctionBodyGenerator { public static final String MAP_ANYDATA = "map "; public static final String MAP_STRING_STRING_ARRAY = "map "; - public static final String GET_MAP_FOR_HEADERS = " = getMapForHeaders("; + public static final String GET_MAP_FOR_HEADERS = " = http:getHeaderMap("; private final List imports; private final String path; protected final Map.Entry operation; @@ -286,11 +286,9 @@ public void handleQueryParamsAndHeaders(List queryParameters, List statementsList, List 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; @@ -230,22 +231,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; -} - isolated function createBodyParts(record {|anydata...;|} anyRecord, map encodingMap = {}) returns mime:Entity[]|error { mime:Entity[] entities = []; foreach [string, anydata] [key, value] in anyRecord.entries() {