Skip to content

Commit

Permalink
Merge pull request #1793 from SachinAkash01/relaxed-data-binding
Browse files Browse the repository at this point in the history
Add Relaxed Data Binding Support for Client Generation
  • Loading branch information
lnash94 authored Nov 27, 2024
2 parents 3c3317b + 77ed3c3 commit 11a335b
Show file tree
Hide file tree
Showing 35 changed files with 172 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ stdlibJwtVersion=2.13.1-20241113-162400-b59ccfa
stdlibOAuth2Version=2.12.1-20241113-162400-4c6ddfe

# Stdlib Level 05
stdlibHttpVersion=2.13.0-20241114-182900-7e9f66a
stdlibHttpVersion=2.13.0-20241126-143900-9551ecd

# Stdlib Level 06
stdlibGrpcVersion=1.13.0-20241114-195700-5188f60
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ public class TestConstants {
" http:ProxyConfig proxy?;\n" +
" # Enables the inbound payload validation functionality which provided by the constraint package. " +
"Enabled by default\n" +
" boolean validation = true; " +
" boolean validation = true;\n" +
" # Enables or disables relaxed data binding on the client side. Disabled by default.\n" +
" # When enabled, the JSON data will be projected to the Ballerina record type and during the " +
"projection, \n" +
" # nil values will be considered as optional fields and absent fields will be considered for " +
"nilable types\n" +
" boolean laxDataBinding = true;\n" +
"|};";

public static final String CLIENT_HTTP1_SETTINGS = "# Provides settings related to HTTP/1.x protocol.\n" +
Expand Down Expand Up @@ -210,6 +216,12 @@ public class TestConstants {
" # Enables the inbound payload validation functionality which provided by the constraint package. " +
"Enabled by default\n" +
" boolean validation = true;\n" +
" # Enables or disables relaxed data binding on the client side. Disabled by default.\n" +
" # When enabled, the JSON data will be projected to the Ballerina record type and during the " +
"projection, \n" +
" # nil values will be considered as optional fields and absent fields will be considered for " +
"nilable types\n" +
" boolean laxDataBinding = true;\n" +
"|};";
public static final String CONNECTION_CONFIG_MIXED_AUTH = "" +
"# Provides a set of configurations for controlling the behaviours when communicating with a " +
Expand Down Expand Up @@ -248,6 +260,12 @@ public class TestConstants {
" # Enables the inbound payload validation functionality which provided by the constraint package. " +
"Enabled by default\n" +
" boolean validation = true;\n" +
" # Enables or disables relaxed data binding on the client side. Disabled by default.\n" +
" # When enabled, the JSON data will be projected to the Ballerina record type and during the " +
"projection, \n" +
" # nil values will be considered as optional fields and absent fields will be considered for " +
"nilable types\n" +
" boolean laxDataBinding = true;\n" +
"|};";

public static final String CONNECTION_CONFIG_HTTP_VERSION_1_1 = "" +
Expand Down Expand Up @@ -284,6 +302,12 @@ public class TestConstants {
" # Enables the inbound payload validation functionality which provided by the constraint package. " +
" Enabled by default\n" +
" boolean validation = true;\n" +
" # Enables or disables relaxed data binding on the client side. Disabled by default.\n" +
" # When enabled, the JSON data will be projected to the Ballerina record type and during the " +
"projection,\n" +
" # nil values will be considered as optional fields and absent fields will be considered for " +
"nilable types\n" +
" boolean laxDataBinding = true;\n" +
"|};";
public static final String OAUTH2_REFRESH_TOKEN_GRANT_CONFIG_RECORD = "#OAuth2ClientCredentialsGrantConfigs" +
"publictypeOAuth2ClientCredentialsGrantConfigrecord{|*http:OAuth2ClientCredentialsGrantConfig;" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,4 +353,8 @@ public type ConnectionConfig record {|
http:ProxyConfig proxy?;
# Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default
boolean validation = true;
# Enables or disables relaxed data binding on the client side. Disabled by default.
# When enabled, the JSON data will be projected to the Ballerina record type and during the projection,
# nil values will be considered as optional fields and absent fields will be considered for nilable types
boolean laxDataBinding = true;
|};
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,8 @@ public type ConnectionConfig record {|
http:ProxyConfig proxy?;
# Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default
boolean validation = true;
# Enables or disables relaxed data binding on the client side. Disabled by default.
# When enabled, the JSON data will be projected to the Ballerina record type and during the projection,
# nil values will be considered as optional fields and absent fields will be considered for nilable types
boolean laxDataBinding = true;
|};
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ public type ConnectionConfig record {|
http:ProxyConfig proxy?;
# Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default
boolean validation = true;
# Enables or disables relaxed data binding on the client side. Disabled by default.
# When enabled, the JSON data will be projected to the Ballerina record type and during the projection,
# nil values will be considered as optional fields and absent fields will be considered for nilable types
boolean laxDataBinding = true;
|};

# Represents the Queries record for the operation: getAlbumsId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ public type ConnectionConfig record {|
http:ProxyConfig proxy?;
# Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default
boolean validation = true;
# Enables or disables relaxed data binding on the client side. Disabled by default.
# When enabled, the JSON data will be projected to the Ballerina record type and during the projection,
# nil values will be considered as optional fields and absent fields will be considered for nilable types
boolean laxDataBinding = true;
|};

# Represents the Queries record for the operation: Get_Albums_Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ public type ConnectionConfig record {|
http:ProxyConfig proxy?;
# Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default
boolean validation = true;
# Enables or disables relaxed data binding on the client side. Disabled by default.
# When enabled, the JSON data will be projected to the Ballerina record type and during the projection,
# nil values will be considered as optional fields and absent fields will be considered for nilable types
boolean laxDataBinding = true;
|};

# Represents the Queries record for the operation: getAlbumsId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6737,6 +6737,10 @@ public type ConnectionConfig record {|
http:ProxyConfig proxy?;
# Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default
boolean validation = true;
# Enables or disables relaxed data binding on the client side. Disabled by default.
# When enabled, the JSON data will be projected to the Ballerina record type and during the projection,
# nil values will be considered as optional fields and absent fields will be considered for nilable types
boolean laxDataBinding = true;
|};

# Represents the Queries record for the operation: getNotificationSchemeForProject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,8 @@ public type ConnectionConfig record {|
http:ProxyConfig proxy?;
# Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default
boolean validation = true;
# Enables or disables relaxed data binding on the client side. Disabled by default.
# When enabled, the JSON data will be projected to the Ballerina record type and during the projection,
# nil values will be considered as optional fields and absent fields will be considered for nilable types
boolean laxDataBinding = true;
|};
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,8 @@ public type ConnectionConfig record {|
http:ProxyConfig proxy?;
# Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default
boolean validation = true;
# Enables or disables relaxed data binding on the client side. Disabled by default.
# When enabled, the JSON data will be projected to the Ballerina record type and during the projection,
# nil values will be considered as optional fields and absent fields will be considered for nilable types
boolean laxDataBinding = true;
|};
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,8 @@ public type ConnectionConfig record {|
http:ProxyConfig proxy?;
# Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default
boolean validation = true;
# Enables or disables relaxed data binding on the client side. Disabled by default.
# When enabled, the JSON data will be projected to the Ballerina record type and during the projection,
# nil values will be considered as optional fields and absent fields will be considered for nilable types
boolean laxDataBinding = true;
|};
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,8 @@ public type ConnectionConfig record {|
http:ProxyConfig proxy?;
# Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default
boolean validation = true;
# Enables or disables relaxed data binding on the client side. Disabled by default.
# When enabled, the JSON data will be projected to the Ballerina record type and during the projection,
# nil values will be considered as optional fields and absent fields will be considered for nilable types
boolean laxDataBinding = true;
|};
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,8 @@ public type ConnectionConfig record {|
http:ProxyConfig proxy?;
# Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default
boolean validation = true;
# Enables or disables relaxed data binding on the client side. Disabled by default.
# When enabled, the JSON data will be projected to the Ballerina record type and during the projection,
# nil values will be considered as optional fields and absent fields will be considered for nilable types
boolean laxDataBinding = true;
|};
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,8 @@ public type ConnectionConfig record {|
http:ProxyConfig proxy?;
# Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default
boolean validation = true;
# Enables or disables relaxed data binding on the client side. Disabled by default.
# When enabled, the JSON data will be projected to the Ballerina record type and during the projection,
# nil values will be considered as optional fields and absent fields will be considered for nilable types
boolean laxDataBinding = true;
|};
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,8 @@ public type ConnectionConfig record {|
http:ProxyConfig proxy?;
# Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default
boolean validation = true;
# Enables or disables relaxed data binding on the client side. Disabled by default.
# When enabled, the JSON data will be projected to the Ballerina record type and during the projection,
# nil values will be considered as optional fields and absent fields will be considered for nilable types
boolean laxDataBinding = true;
|};
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,8 @@ public type ConnectionConfig record {|
http:ProxyConfig proxy?;
# Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default
boolean validation = true;
# Enables or disables relaxed data binding on the client side. Disabled by default.
# When enabled, the JSON data will be projected to the Ballerina record type and during the projection,
# nil values will be considered as optional fields and absent fields will be considered for nilable types
boolean laxDataBinding = true;
|};
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,8 @@ public type ConnectionConfig record {|
http:ProxyConfig proxy?;
# Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default
boolean validation = true;
# Enables or disables relaxed data binding on the client side. Disabled by default.
# When enabled, the JSON data will be projected to the Ballerina record type and during the projection,
# nil values will be considered as optional fields and absent fields will be considered for nilable types
boolean laxDataBinding = true;
|};
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,8 @@ public type ConnectionConfig record {|
http:ProxyConfig proxy?;
# Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default
boolean validation = true;
# Enables or disables relaxed data binding on the client side. Disabled by default.
# When enabled, the JSON data will be projected to the Ballerina record type and during the projection,
# nil values will be considered as optional fields and absent fields will be considered for nilable types
boolean laxDataBinding = true;
|};
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,8 @@ public type ConnectionConfig record {|
http:ProxyConfig proxy?;
# Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default
boolean validation = true;
# Enables or disables relaxed data binding on the client side. Disabled by default.
# When enabled, the JSON data will be projected to the Ballerina record type and during the projection,
# nil values will be considered as optional fields and absent fields will be considered for nilable types
boolean laxDataBinding = true;
|};
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,8 @@ public type ConnectionConfig record {|
http:ProxyConfig proxy?;
# Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default
boolean validation = true;
# Enables or disables relaxed data binding on the client side. Disabled by default.
# When enabled, the JSON data will be projected to the Ballerina record type and during the projection,
# nil values will be considered as optional fields and absent fields will be considered for nilable types
boolean laxDataBinding = true;
|};
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,8 @@ public type ConnectionConfig record {|
http:ProxyConfig proxy?;
# Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default
boolean validation = true;
# Enables or disables relaxed data binding on the client side. Disabled by default.
# When enabled, the JSON data will be projected to the Ballerina record type and during the projection,
# nil values will be considered as optional fields and absent fields will be considered for nilable types
boolean laxDataBinding = true;
|};
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,8 @@ public type ConnectionConfig record {|
http:ProxyConfig proxy?;
# Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default
boolean validation = true;
# Enables or disables relaxed data binding on the client side. Disabled by default.
# When enabled, the JSON data will be projected to the Ballerina record type and during the projection,
# nil values will be considered as optional fields and absent fields will be considered for nilable types
boolean laxDataBinding = true;
|};
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,8 @@ public type ConnectionConfig record {|
http:ProxyConfig proxy?;
# Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default
boolean validation = true;
# Enables or disables relaxed data binding on the client side. Disabled by default.
# When enabled, the JSON data will be projected to the Ballerina record type and during the projection,
# nil values will be considered as optional fields and absent fields will be considered for nilable types
boolean laxDataBinding = true;
|};
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,11 @@ public void addAuthRelatedRecords(OpenAPI openAPI) throws ClientException {
* # Enables the inbound payload validation functionality which provided by the constraint package.
* # Enabled by default
* boolean validation = true;
* # Enables or disables relaxed data binding on the service side. Disabled by default.
* # When enabled, the JSON data will be projected to the Ballerina record type and during the projection,
* # nil values will be considered as optional fields and absent fields will be considered for
* # nilable types
* boolean laxDataBinding = true;
* |};
* </pre>
* Scenario 1 : For openapi contracts with no authentication mechanism given, auth field will not be generated
Expand Down Expand Up @@ -1333,6 +1338,19 @@ private List<Node> getClientConfigRecordFields() {
validationMetadata, null, validationFieldType, validationFieldName,
equalToken, createRequiredExpressionNode(createToken(TRUE_KEYWORD)), semicolonToken);
recordFieldNodes.add(validateFieldNode);

// add laxBinding for data binding
String apiComment = "Enables or disables relaxed data binding on the client side. " +
"Disabled by default.\nWhen enabled, the JSON data will be projected to the Ballerina record type" +
" and during the projection, \nnil values will be considered as optional fields and absent fields " +
"will be considered for nilable types";
MetadataNode laxDataBindingMetadata = getMetadataNode(apiComment);
IdentifierToken laxDataBindingFieldName = AbstractNodeFactory.createIdentifierToken("laxDataBinding");
TypeDescriptorNode laxDataBindingFieldType = createSimpleNameReferenceNode(createIdentifierToken(BOOLEAN));
RecordFieldWithDefaultValueNode laxDataBindingFieldNode = NodeFactory.createRecordFieldWithDefaultValueNode(
laxDataBindingMetadata, null, laxDataBindingFieldType, laxDataBindingFieldName,
equalToken, createRequiredExpressionNode(createToken(TRUE_KEYWORD)), semicolonToken);
recordFieldNodes.add(laxDataBindingFieldNode);
return recordFieldNodes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,8 @@ public type ConnectionConfig record {|
http:ProxyConfig proxy?;
# Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default
boolean validation = true;
# Enables or disables relaxed data binding on the client side. Disabled by default.
# When enabled, the JSON data will be projected to the Ballerina record type and during the projection,
# nil values will be considered as optional fields and absent fields will be considered for nilable types
boolean laxDataBinding = true;
|};
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ public type ConnectionConfig record {|
http:ProxyConfig proxy?;
# Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default
boolean validation = true;
# Enables or disables relaxed data binding on the client side. Disabled by default.
# When enabled, the JSON data will be projected to the Ballerina record type and during the projection,
# nil values will be considered as optional fields and absent fields will be considered for nilable types
boolean laxDataBinding = true;
|};

# Request for the chat completions using extensions
Expand Down
Loading

0 comments on commit 11a335b

Please sign in to comment.