From 2cbf0b5ebeb3943764edf110bf0b5cf48a82fb9c Mon Sep 17 00:00:00 2001 From: SachinAkash01 Date: Tue, 26 Nov 2024 14:56:36 +0530 Subject: [PATCH 1/3] Update AuthConfigGeneratorImp with laxDataBinding --- .../client/AuthConfigGeneratorImp.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/openapi-core/src/main/java/io/ballerina/openapi/core/generators/client/AuthConfigGeneratorImp.java b/openapi-core/src/main/java/io/ballerina/openapi/core/generators/client/AuthConfigGeneratorImp.java index 2bd693ef1..a4ccbf324 100644 --- a/openapi-core/src/main/java/io/ballerina/openapi/core/generators/client/AuthConfigGeneratorImp.java +++ b/openapi-core/src/main/java/io/ballerina/openapi/core/generators/client/AuthConfigGeneratorImp.java @@ -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; * |}; * * Scenario 1 : For openapi contracts with no authentication mechanism given, auth field will not be generated @@ -1333,6 +1338,18 @@ private List getClientConfigRecordFields() { validationMetadata, null, validationFieldType, validationFieldName, equalToken, createRequiredExpressionNode(createToken(TRUE_KEYWORD)), semicolonToken); recordFieldNodes.add(validateFieldNode); + + // add laxBinding for data binding + MetadataNode laxDataBindingMetadata = getMetadataNode("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"); + 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; } From fc886fdf7097238e3a9ee10605981192012d598a Mon Sep 17 00:00:00 2001 From: SachinAkash01 Date: Wed, 27 Nov 2024 09:52:12 +0530 Subject: [PATCH 2/3] Add support for relaxed data binding for the client generation --- gradle.properties | 2 +- .../generators/common/TestConstants.java | 26 ++++++++++++++++++- .../expected_gen/bal_name_ext_client.bal | 4 +++ .../expected_gen/constraint_import_types.bal | 4 +++ .../default_headers_conflict_with_query.bal | 4 +++ .../default_headers_queries_parameters.bal | 4 +++ .../default_value_generation_client.bal | 4 +++ .../expected_gen/jira_openapi_client.bal | 4 +++ .../expected_gen/licenses/schema.bal | 4 +++ .../schema_for_both_service_client.bal | 4 +++ .../schema_with_user_given_license.bal | 4 +++ ...es_for_both_service_client_generations.bal | 4 +++ .../non_constraint_import_types.bal | 4 +++ .../expected_gen/nullable_false_types.bal | 4 +++ .../resources/expected_gen/nullable_types.bal | 4 +++ .../expected_gen/petstore_schema.bal | 4 +++ .../expected_gen/petstore_schema_2.bal | 4 +++ .../expected_gen/petstore_schema_type.bal | 4 +++ .../petstore_schema_with_license.bal | 4 +++ .../expected_gen/sanitize_array_member.bal | 4 +++ .../expected_gen/type_filtered_by_tags.bal | 4 +++ .../type_name_with_mixed_case.bal | 4 +++ .../client/ballerina/union_path_types.bal | 4 +++ .../client/AuthConfigGeneratorImp.java | 9 ++++--- .../client/expected/project-09/types.bal | 4 +++ .../client/expected/project-10/types.bal | 4 +++ .../client/project-expected/types.bal | 4 +++ .../client/project-expected/types_all.bal | 4 +++ .../types_all_with_default.bal | 4 +++ .../project-expected/types_with_default.bal | 4 +++ .../src/test/resources/schema/array.bal | 4 +++ .../schema/non_ecma_string_pattern.bal | 4 +++ .../src/test/resources/schema/union.bal | 4 +++ .../schema/unsupported_string_pattern.bal | 4 +++ 34 files changed, 155 insertions(+), 6 deletions(-) diff --git a/gradle.properties b/gradle.properties index 087560724..4934e0a13 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/openapi-cli/src/test/java/io/ballerina/openapi/generators/common/TestConstants.java b/openapi-cli/src/test/java/io/ballerina/openapi/generators/common/TestConstants.java index ce1c1e1e6..cbcaab206 100644 --- a/openapi-cli/src/test/java/io/ballerina/openapi/generators/common/TestConstants.java +++ b/openapi-cli/src/test/java/io/ballerina/openapi/generators/common/TestConstants.java @@ -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" + @@ -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 " + @@ -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 = "" + @@ -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;" + diff --git a/openapi-cli/src/test/resources/expected_gen/bal_name_ext_client.bal b/openapi-cli/src/test/resources/expected_gen/bal_name_ext_client.bal index c33efdb84..62a1d9fb3 100644 --- a/openapi-cli/src/test/resources/expected_gen/bal_name_ext_client.bal +++ b/openapi-cli/src/test/resources/expected_gen/bal_name_ext_client.bal @@ -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; |}; diff --git a/openapi-cli/src/test/resources/expected_gen/constraint_import_types.bal b/openapi-cli/src/test/resources/expected_gen/constraint_import_types.bal index 14597b0e3..d1b254762 100644 --- a/openapi-cli/src/test/resources/expected_gen/constraint_import_types.bal +++ b/openapi-cli/src/test/resources/expected_gen/constraint_import_types.bal @@ -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; |}; 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 dd57d7110..6d68e5555 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 @@ -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 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 376268f53..ec4f0bbfe 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 @@ -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 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 1771e5cbe..d86070b23 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 @@ -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 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 a1219ac5f..10370c143 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 @@ -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 diff --git a/openapi-cli/src/test/resources/expected_gen/licenses/schema.bal b/openapi-cli/src/test/resources/expected_gen/licenses/schema.bal index 16b0d2801..1c1ffc66b 100644 --- a/openapi-cli/src/test/resources/expected_gen/licenses/schema.bal +++ b/openapi-cli/src/test/resources/expected_gen/licenses/schema.bal @@ -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; |}; diff --git a/openapi-cli/src/test/resources/expected_gen/licenses/schema_for_both_service_client.bal b/openapi-cli/src/test/resources/expected_gen/licenses/schema_for_both_service_client.bal index daa48a5a0..2ffd09b61 100644 --- a/openapi-cli/src/test/resources/expected_gen/licenses/schema_for_both_service_client.bal +++ b/openapi-cli/src/test/resources/expected_gen/licenses/schema_for_both_service_client.bal @@ -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; |}; diff --git a/openapi-cli/src/test/resources/expected_gen/licenses/schema_with_user_given_license.bal b/openapi-cli/src/test/resources/expected_gen/licenses/schema_with_user_given_license.bal index 8c9a283a3..87023bfb8 100644 --- a/openapi-cli/src/test/resources/expected_gen/licenses/schema_with_user_given_license.bal +++ b/openapi-cli/src/test/resources/expected_gen/licenses/schema_with_user_given_license.bal @@ -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; |}; diff --git a/openapi-cli/src/test/resources/expected_gen/licenses/types_for_both_service_client_generations.bal b/openapi-cli/src/test/resources/expected_gen/licenses/types_for_both_service_client_generations.bal index daa48a5a0..2ffd09b61 100644 --- a/openapi-cli/src/test/resources/expected_gen/licenses/types_for_both_service_client_generations.bal +++ b/openapi-cli/src/test/resources/expected_gen/licenses/types_for_both_service_client_generations.bal @@ -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; |}; diff --git a/openapi-cli/src/test/resources/expected_gen/non_constraint_import_types.bal b/openapi-cli/src/test/resources/expected_gen/non_constraint_import_types.bal index fb219c0bf..109ad22b8 100644 --- a/openapi-cli/src/test/resources/expected_gen/non_constraint_import_types.bal +++ b/openapi-cli/src/test/resources/expected_gen/non_constraint_import_types.bal @@ -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; |}; diff --git a/openapi-cli/src/test/resources/expected_gen/nullable_false_types.bal b/openapi-cli/src/test/resources/expected_gen/nullable_false_types.bal index e329fad33..b5fe05513 100644 --- a/openapi-cli/src/test/resources/expected_gen/nullable_false_types.bal +++ b/openapi-cli/src/test/resources/expected_gen/nullable_false_types.bal @@ -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; |}; diff --git a/openapi-cli/src/test/resources/expected_gen/nullable_types.bal b/openapi-cli/src/test/resources/expected_gen/nullable_types.bal index 4f4880afc..3414b50d2 100644 --- a/openapi-cli/src/test/resources/expected_gen/nullable_types.bal +++ b/openapi-cli/src/test/resources/expected_gen/nullable_types.bal @@ -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; |}; diff --git a/openapi-cli/src/test/resources/expected_gen/petstore_schema.bal b/openapi-cli/src/test/resources/expected_gen/petstore_schema.bal index daa48a5a0..2ffd09b61 100644 --- a/openapi-cli/src/test/resources/expected_gen/petstore_schema.bal +++ b/openapi-cli/src/test/resources/expected_gen/petstore_schema.bal @@ -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; |}; diff --git a/openapi-cli/src/test/resources/expected_gen/petstore_schema_2.bal b/openapi-cli/src/test/resources/expected_gen/petstore_schema_2.bal index 07e413ffa..47778150f 100644 --- a/openapi-cli/src/test/resources/expected_gen/petstore_schema_2.bal +++ b/openapi-cli/src/test/resources/expected_gen/petstore_schema_2.bal @@ -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; |}; diff --git a/openapi-cli/src/test/resources/expected_gen/petstore_schema_type.bal b/openapi-cli/src/test/resources/expected_gen/petstore_schema_type.bal index 2dd54d13a..e6c35ed10 100644 --- a/openapi-cli/src/test/resources/expected_gen/petstore_schema_type.bal +++ b/openapi-cli/src/test/resources/expected_gen/petstore_schema_type.bal @@ -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; |}; diff --git a/openapi-cli/src/test/resources/expected_gen/petstore_schema_with_license.bal b/openapi-cli/src/test/resources/expected_gen/petstore_schema_with_license.bal index b84d79898..99849d6eb 100644 --- a/openapi-cli/src/test/resources/expected_gen/petstore_schema_with_license.bal +++ b/openapi-cli/src/test/resources/expected_gen/petstore_schema_with_license.bal @@ -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; |}; 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 bfc332d5a..186664d8e 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 @@ -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; |}; diff --git a/openapi-cli/src/test/resources/expected_gen/type_filtered_by_tags.bal b/openapi-cli/src/test/resources/expected_gen/type_filtered_by_tags.bal index 16b0d2801..1c1ffc66b 100644 --- a/openapi-cli/src/test/resources/expected_gen/type_filtered_by_tags.bal +++ b/openapi-cli/src/test/resources/expected_gen/type_filtered_by_tags.bal @@ -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; |}; 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 5cd194f0a..b37ec6160 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 @@ -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; |}; diff --git a/openapi-cli/src/test/resources/generators/client/ballerina/union_path_types.bal b/openapi-cli/src/test/resources/generators/client/ballerina/union_path_types.bal index 1fb5d56d1..8e40bbaeb 100644 --- a/openapi-cli/src/test/resources/generators/client/ballerina/union_path_types.bal +++ b/openapi-cli/src/test/resources/generators/client/ballerina/union_path_types.bal @@ -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; |}; diff --git a/openapi-core/src/main/java/io/ballerina/openapi/core/generators/client/AuthConfigGeneratorImp.java b/openapi-core/src/main/java/io/ballerina/openapi/core/generators/client/AuthConfigGeneratorImp.java index a4ccbf324..2cf7edc6a 100644 --- a/openapi-core/src/main/java/io/ballerina/openapi/core/generators/client/AuthConfigGeneratorImp.java +++ b/openapi-core/src/main/java/io/ballerina/openapi/core/generators/client/AuthConfigGeneratorImp.java @@ -1340,10 +1340,11 @@ private List getClientConfigRecordFields() { recordFieldNodes.add(validateFieldNode); // add laxBinding for data binding - MetadataNode laxDataBindingMetadata = getMetadataNode("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"); + 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( diff --git a/openapi-integration-tests/src/test/resources/client/expected/project-09/types.bal b/openapi-integration-tests/src/test/resources/client/expected/project-09/types.bal index 347517198..e07cee5d8 100644 --- a/openapi-integration-tests/src/test/resources/client/expected/project-09/types.bal +++ b/openapi-integration-tests/src/test/resources/client/expected/project-09/types.bal @@ -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 diff --git a/openapi-integration-tests/src/test/resources/client/expected/project-10/types.bal b/openapi-integration-tests/src/test/resources/client/expected/project-10/types.bal index a52e145c7..1ed73ca32 100644 --- a/openapi-integration-tests/src/test/resources/client/expected/project-10/types.bal +++ b/openapi-integration-tests/src/test/resources/client/expected/project-10/types.bal @@ -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; |}; diff --git a/openapi-integration-tests/src/test/resources/client/project-expected/types.bal b/openapi-integration-tests/src/test/resources/client/project-expected/types.bal index ec4d57fdf..050352005 100644 --- a/openapi-integration-tests/src/test/resources/client/project-expected/types.bal +++ b/openapi-integration-tests/src/test/resources/client/project-expected/types.bal @@ -118,4 +118,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; |}; diff --git a/openapi-integration-tests/src/test/resources/client/project-expected/types_all.bal b/openapi-integration-tests/src/test/resources/client/project-expected/types_all.bal index b191ef41c..48a5cef24 100644 --- a/openapi-integration-tests/src/test/resources/client/project-expected/types_all.bal +++ b/openapi-integration-tests/src/test/resources/client/project-expected/types_all.bal @@ -118,4 +118,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; |}; diff --git a/openapi-integration-tests/src/test/resources/client/project-expected/types_all_with_default.bal b/openapi-integration-tests/src/test/resources/client/project-expected/types_all_with_default.bal index a71fd608a..a4f66239d 100644 --- a/openapi-integration-tests/src/test/resources/client/project-expected/types_all_with_default.bal +++ b/openapi-integration-tests/src/test/resources/client/project-expected/types_all_with_default.bal @@ -98,4 +98,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; |}; diff --git a/openapi-integration-tests/src/test/resources/client/project-expected/types_with_default.bal b/openapi-integration-tests/src/test/resources/client/project-expected/types_with_default.bal index c41121fa5..a082a28cf 100644 --- a/openapi-integration-tests/src/test/resources/client/project-expected/types_with_default.bal +++ b/openapi-integration-tests/src/test/resources/client/project-expected/types_with_default.bal @@ -98,4 +98,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; |}; diff --git a/openapi-integration-tests/src/test/resources/schema/array.bal b/openapi-integration-tests/src/test/resources/schema/array.bal index 0eaf0ad5a..90802c8d5 100644 --- a/openapi-integration-tests/src/test/resources/schema/array.bal +++ b/openapi-integration-tests/src/test/resources/schema/array.bal @@ -59,4 +59,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; |}; diff --git a/openapi-integration-tests/src/test/resources/schema/non_ecma_string_pattern.bal b/openapi-integration-tests/src/test/resources/schema/non_ecma_string_pattern.bal index 9e0a358e5..341d3cb61 100644 --- a/openapi-integration-tests/src/test/resources/schema/non_ecma_string_pattern.bal +++ b/openapi-integration-tests/src/test/resources/schema/non_ecma_string_pattern.bal @@ -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; |}; diff --git a/openapi-integration-tests/src/test/resources/schema/union.bal b/openapi-integration-tests/src/test/resources/schema/union.bal index de0784a53..69cb1c824 100644 --- a/openapi-integration-tests/src/test/resources/schema/union.bal +++ b/openapi-integration-tests/src/test/resources/schema/union.bal @@ -78,4 +78,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; |}; diff --git a/openapi-integration-tests/src/test/resources/schema/unsupported_string_pattern.bal b/openapi-integration-tests/src/test/resources/schema/unsupported_string_pattern.bal index 8a5e57577..a79069763 100644 --- a/openapi-integration-tests/src/test/resources/schema/unsupported_string_pattern.bal +++ b/openapi-integration-tests/src/test/resources/schema/unsupported_string_pattern.bal @@ -70,4 +70,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; |}; From 77ed3c3752478a06a82027cf8e5c455038ad6d82 Mon Sep 17 00:00:00 2001 From: SachinAkash01 Date: Wed, 27 Nov 2024 11:47:36 +0530 Subject: [PATCH 3/3] Fix failing integration tests --- .../resources/ballerina_sources/resources/expected_types.bal | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/openapi-integration-tests/src/test/resources/ballerina_sources/resources/expected_types.bal b/openapi-integration-tests/src/test/resources/ballerina_sources/resources/expected_types.bal index d7dd22840..a8e945459 100644 --- a/openapi-integration-tests/src/test/resources/ballerina_sources/resources/expected_types.bal +++ b/openapi-integration-tests/src/test/resources/ballerina_sources/resources/expected_types.bal @@ -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; |};