diff --git a/runtime/config-deployer-service/ballerina/APIClient.bal b/runtime/config-deployer-service/ballerina/APIClient.bal index 72096f208c..174b57dca5 100644 --- a/runtime/config-deployer-service/ballerina/APIClient.bal +++ b/runtime/config-deployer-service/ballerina/APIClient.bal @@ -361,9 +361,17 @@ public class APIClient { authTypes.jwt = {header: jwtAuthentication.headerName, sendTokenToUpstream: jwtAuthentication.sendTokenToUpstream, disabled: !jwtAuthentication.enabled, audience: jwtAuthentication.audience}; } else if authentication.authType == "APIKey" && authentication is APIKeyAuthentication { APIKeyAuthentication apiKeyAuthentication = check authentication.cloneWithType(APIKeyAuthentication); - authTypes.apiKey = []; - authTypes.apiKey.push({'in: "Header", name: apiKeyAuthentication.headerName, sendTokenToUpstream: apiKeyAuthentication.sendTokenToUpstream}); - authTypes.apiKey.push({'in: "Query", name: apiKeyAuthentication.queryParamName, sendTokenToUpstream: apiKeyAuthentication.sendTokenToUpstream}); + model:APIKey[] apiKeys = []; + boolean|() headerEnabled = apiKeyAuthentication.headerEnable; + boolean|() queryEnabled = apiKeyAuthentication.queryParamEnable; + + if headerEnabled is boolean && headerEnabled { + apiKeys.push({'in: "Header", name: apiKeyAuthentication.headerName, sendTokenToUpstream: apiKeyAuthentication.sendTokenToUpstream}); + } + if queryEnabled is boolean && queryEnabled { + apiKeys.push({'in: "Query", name: apiKeyAuthentication.queryParamName, sendTokenToUpstream: apiKeyAuthentication.sendTokenToUpstream}); + } + authTypes.apiKey = apiKeys; } else if authentication.authType == "mTLS" { MTLSAuthentication mtlsAuthentication = check authentication.cloneWithType(MTLSAuthentication); isMTLSMandatory = mtlsAuthentication.required == "mandatory"; diff --git a/runtime/config-deployer-service/ballerina/types.bal b/runtime/config-deployer-service/ballerina/types.bal index 66d04272f4..90f428ffaa 100644 --- a/runtime/config-deployer-service/ballerina/types.bal +++ b/runtime/config-deployer-service/ballerina/types.bal @@ -275,8 +275,8 @@ public type APIKeyAuthentication record {| boolean sendTokenToUpstream = false; string headerName = "apiKey"; string queryParamName = "apiKey"; - boolean headerEnable = true; - boolean queryParamEnable = true; + boolean headerEnable?; + boolean queryParamEnable?; |}; # Mutual SSL configuration of this API