Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Relaxed Data Binding Support for Client Generation #1793

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Enables or disables relaxed data binding on the client side. Disabled by default.
# Enables or disables relaxed data binding on the client side. Enabled 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";
Comment on lines +1343 to +1346
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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";
String apiComment = "Enables relaxed data binding on the client side. When enabled, `nil` values are treated as optional, \nand absent fields are handled as `nilable` types. Enabled by default.";

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

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