From 363906fda35d500e94adff142a346ff3a940c93c Mon Sep 17 00:00:00 2001 From: William Cheng Date: Mon, 7 Nov 2022 02:16:16 +0800 Subject: [PATCH] Better error check if discriminator value is null in r client (#13930) * better error check if discriminator value is null in r client * more readable error messages --- .../src/main/resources/r/modelAnyOf.mustache | 4 ++-- .../src/main/resources/r/modelOneOf.mustache | 12 ++++++++---- .../client/petstore/R-httr2-wrapper/R/any_of_pig.R | 4 ++-- .../R-httr2-wrapper/R/any_of_primitive_type_test.R | 7 ++++--- samples/client/petstore/R-httr2-wrapper/R/mammal.R | 12 ++++++++---- .../R-httr2-wrapper/R/one_of_primitive_type_test.R | 7 ++++--- samples/client/petstore/R-httr2-wrapper/R/pig.R | 12 ++++++++---- .../R-httr2-wrapper/tests/testthat/test_petstore.R | 8 ++++---- samples/client/petstore/R-httr2/R/any_of_pig.R | 4 ++-- .../petstore/R-httr2/R/any_of_primitive_type_test.R | 7 ++++--- samples/client/petstore/R-httr2/R/mammal.R | 7 ++++--- .../petstore/R-httr2/R/one_of_primitive_type_test.R | 7 ++++--- samples/client/petstore/R-httr2/R/pig.R | 7 ++++--- .../petstore/R-httr2/tests/testthat/test_petstore.R | 12 ++++++------ samples/client/petstore/R/R/any_of_pig.R | 4 ++-- .../client/petstore/R/R/any_of_primitive_type_test.R | 7 ++++--- samples/client/petstore/R/R/mammal.R | 7 ++++--- .../client/petstore/R/R/one_of_primitive_type_test.R | 7 ++++--- samples/client/petstore/R/R/pig.R | 7 ++++--- .../client/petstore/R/tests/testthat/test_petstore.R | 8 ++++---- 20 files changed, 86 insertions(+), 64 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/r/modelAnyOf.mustache b/modules/openapi-generator/src/main/resources/r/modelAnyOf.mustache index ba288abfabd..84cc761b407 100644 --- a/modules/openapi-generator/src/main/resources/r/modelAnyOf.mustache +++ b/modules/openapi-generator/src/main/resources/r/modelAnyOf.mustache @@ -85,8 +85,8 @@ {{/isNull}} {{/composedSchemas.anyOf}} # no match - stop(paste("No match found when deserializing the payload into {{{classname}}} with anyOf schemas {{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}. Details: ", - paste(error_messages, collapse = ", "))) + stop(paste("No match found when deserializing the input into {{{classname}}} with anyOf schemas {{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}. Details: >>", + paste(error_messages, collapse = " >> "))) }, #' Serialize {{{classname}}} to JSON string. #' diff --git a/modules/openapi-generator/src/main/resources/r/modelOneOf.mustache b/modules/openapi-generator/src/main/resources/r/modelOneOf.mustache index 7211b50ed8b..da27bdfb2d7 100644 --- a/modules/openapi-generator/src/main/resources/r/modelOneOf.mustache +++ b/modules/openapi-generator/src/main/resources/r/modelOneOf.mustache @@ -65,6 +65,9 @@ {{#discriminator}} oneof_lookup_result <- tryCatch({ discriminatorValue <- (jsonlite::fromJSON(input, simplifyVector = FALSE))$`{{{propertyBaseName}}}` + if (is.null(discriminatorValue)) { # throw error if it's null + stop("Error! The value of the discriminator property `{{{propertyBaseName}}}`, which should be the class type, is null") + } switch(discriminatorValue, {{#mappedModels}} {{{mappingName}}}={ @@ -89,7 +92,7 @@ error = function(err) err ) if (!is.null(oneof_lookup_result["error"])) { - error_messages <- append(error_messages, sprintf("Failed to lookup discriminator value for {{classname}}. Error message: %s. Input: %s", oneof_lookup_result["message"], input)) + error_messages <- append(error_messages, sprintf("Failed to lookup discriminator value for {{classname}}. Error message: %s. JSON input: %s", oneof_lookup_result["message"], input)) } {{/discriminator}} @@ -127,11 +130,12 @@ self$actual_type <- instance_type } else if (matched > 1) { # more than 1 match - stop("Multiple matches found when deserializing the payload into {{{classname}}} with oneOf schemas {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}.") + stop(paste("Multiple matches found when deserializing the input into {{{classname}}} with oneOf schemas {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}. Matched schemas: ", + paste(matched_schemas, collapse = ", "))) } else { # no match - stop(paste("No match found when deserializing the payload into {{{classname}}} with oneOf schemas {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}. Details: ", - paste(error_messages, collapse = ", "))) + stop(paste("No match found when deserializing the input into {{{classname}}} with oneOf schemas {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}. Details: >>", + paste(error_messages, collapse = " >> "))) } self diff --git a/samples/client/petstore/R-httr2-wrapper/R/any_of_pig.R b/samples/client/petstore/R-httr2-wrapper/R/any_of_pig.R index 404b7104727..64e859d560b 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/any_of_pig.R +++ b/samples/client/petstore/R-httr2-wrapper/R/any_of_pig.R @@ -90,8 +90,8 @@ AnyOfPig <- R6::R6Class( } # no match - stop(paste("No match found when deserializing the payload into AnyOfPig with anyOf schemas BasquePig, DanishPig. Details: ", - paste(error_messages, collapse = ", "))) + stop(paste("No match found when deserializing the input into AnyOfPig with anyOf schemas BasquePig, DanishPig. Details: >>", + paste(error_messages, collapse = " >> "))) }, #' Serialize AnyOfPig to JSON string. #' diff --git a/samples/client/petstore/R-httr2-wrapper/R/any_of_primitive_type_test.R b/samples/client/petstore/R-httr2-wrapper/R/any_of_primitive_type_test.R index 374aa8c6057..da1e53ce472 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/any_of_primitive_type_test.R +++ b/samples/client/petstore/R-httr2-wrapper/R/any_of_primitive_type_test.R @@ -102,11 +102,12 @@ AnyOfPrimitiveTypeTest <- R6::R6Class( self$actual_type <- instance_type } else if (matched > 1) { # more than 1 match - stop("Multiple matches found when deserializing the payload into AnyOfPrimitiveTypeTest with oneOf schemas character, integer.") + stop(paste("Multiple matches found when deserializing the input into AnyOfPrimitiveTypeTest with oneOf schemas character, integer. Matched schemas: ", + paste(matched_schemas, collapse = ", "))) } else { # no match - stop(paste("No match found when deserializing the payload into AnyOfPrimitiveTypeTest with oneOf schemas character, integer. Details: ", - paste(error_messages, collapse = ", "))) + stop(paste("No match found when deserializing the input into AnyOfPrimitiveTypeTest with oneOf schemas character, integer. Details: >>", + paste(error_messages, collapse = " >> "))) } self diff --git a/samples/client/petstore/R-httr2-wrapper/R/mammal.R b/samples/client/petstore/R-httr2-wrapper/R/mammal.R index 8ac1d6829dd..c9dd60c3e7c 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/mammal.R +++ b/samples/client/petstore/R-httr2-wrapper/R/mammal.R @@ -66,6 +66,9 @@ Mammal <- R6::R6Class( oneof_lookup_result <- tryCatch({ discriminatorValue <- (jsonlite::fromJSON(input, simplifyVector = FALSE))$`className` + if (is.null(discriminatorValue)) { # throw error if it's null + stop("Error! The value of the discriminator property `className`, which should be the class type, is null") + } switch(discriminatorValue, whale={ Whale$public_methods$validateJSON(input) @@ -84,7 +87,7 @@ Mammal <- R6::R6Class( error = function(err) err ) if (!is.null(oneof_lookup_result["error"])) { - error_messages <- append(error_messages, sprintf("Failed to lookup discriminator value for Mammal. Error message: %s. Input: %s", oneof_lookup_result["message"], input)) + error_messages <- append(error_messages, sprintf("Failed to lookup discriminator value for Mammal. Error message: %s. JSON input: %s", oneof_lookup_result["message"], input)) } Whale_result <- tryCatch({ @@ -123,11 +126,12 @@ Mammal <- R6::R6Class( self$actual_type <- instance_type } else if (matched > 1) { # more than 1 match - stop("Multiple matches found when deserializing the payload into Mammal with oneOf schemas Whale, Zebra.") + stop(paste("Multiple matches found when deserializing the input into Mammal with oneOf schemas Whale, Zebra. Matched schemas: ", + paste(matched_schemas, collapse = ", "))) } else { # no match - stop(paste("No match found when deserializing the payload into Mammal with oneOf schemas Whale, Zebra. Details: ", - paste(error_messages, collapse = ", "))) + stop(paste("No match found when deserializing the input into Mammal with oneOf schemas Whale, Zebra. Details: >>", + paste(error_messages, collapse = " >> "))) } self diff --git a/samples/client/petstore/R-httr2-wrapper/R/one_of_primitive_type_test.R b/samples/client/petstore/R-httr2-wrapper/R/one_of_primitive_type_test.R index d558c0eb507..ed13169f902 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/one_of_primitive_type_test.R +++ b/samples/client/petstore/R-httr2-wrapper/R/one_of_primitive_type_test.R @@ -102,11 +102,12 @@ OneOfPrimitiveTypeTest <- R6::R6Class( self$actual_type <- instance_type } else if (matched > 1) { # more than 1 match - stop("Multiple matches found when deserializing the payload into OneOfPrimitiveTypeTest with oneOf schemas character, integer.") + stop(paste("Multiple matches found when deserializing the input into OneOfPrimitiveTypeTest with oneOf schemas character, integer. Matched schemas: ", + paste(matched_schemas, collapse = ", "))) } else { # no match - stop(paste("No match found when deserializing the payload into OneOfPrimitiveTypeTest with oneOf schemas character, integer. Details: ", - paste(error_messages, collapse = ", "))) + stop(paste("No match found when deserializing the input into OneOfPrimitiveTypeTest with oneOf schemas character, integer. Details: >>", + paste(error_messages, collapse = " >> "))) } self diff --git a/samples/client/petstore/R-httr2-wrapper/R/pig.R b/samples/client/petstore/R-httr2-wrapper/R/pig.R index 0a95e9dec70..f5d81b79392 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/pig.R +++ b/samples/client/petstore/R-httr2-wrapper/R/pig.R @@ -66,6 +66,9 @@ Pig <- R6::R6Class( oneof_lookup_result <- tryCatch({ discriminatorValue <- (jsonlite::fromJSON(input, simplifyVector = FALSE))$`className` + if (is.null(discriminatorValue)) { # throw error if it's null + stop("Error! The value of the discriminator property `className`, which should be the class type, is null") + } switch(discriminatorValue, BasquePig={ BasquePig$public_methods$validateJSON(input) @@ -84,7 +87,7 @@ Pig <- R6::R6Class( error = function(err) err ) if (!is.null(oneof_lookup_result["error"])) { - error_messages <- append(error_messages, sprintf("Failed to lookup discriminator value for Pig. Error message: %s. Input: %s", oneof_lookup_result["message"], input)) + error_messages <- append(error_messages, sprintf("Failed to lookup discriminator value for Pig. Error message: %s. JSON input: %s", oneof_lookup_result["message"], input)) } BasquePig_result <- tryCatch({ @@ -123,11 +126,12 @@ Pig <- R6::R6Class( self$actual_type <- instance_type } else if (matched > 1) { # more than 1 match - stop("Multiple matches found when deserializing the payload into Pig with oneOf schemas BasquePig, DanishPig.") + stop(paste("Multiple matches found when deserializing the input into Pig with oneOf schemas BasquePig, DanishPig. Matched schemas: ", + paste(matched_schemas, collapse = ", "))) } else { # no match - stop(paste("No match found when deserializing the payload into Pig with oneOf schemas BasquePig, DanishPig. Details: ", - paste(error_messages, collapse = ", "))) + stop(paste("No match found when deserializing the input into Pig with oneOf schemas BasquePig, DanishPig. Details: >>", + paste(error_messages, collapse = " >> "))) } self diff --git a/samples/client/petstore/R-httr2-wrapper/tests/testthat/test_petstore.R b/samples/client/petstore/R-httr2-wrapper/tests/testthat/test_petstore.R index 38ce56f5733..df15619de1b 100644 --- a/samples/client/petstore/R-httr2-wrapper/tests/testthat/test_petstore.R +++ b/samples/client/petstore/R-httr2-wrapper/tests/testthat/test_petstore.R @@ -518,8 +518,8 @@ test_that("Tests oneOf", { expect_equal(basque_pig$toJSONString(), original_basque_pig$toJSONString()) # test exception when no matche found - expect_error(pig$fromJSON('{}'), 'No match found when deserializing the payload into Pig with oneOf schemas BasquePig, DanishPig. Details: Failed to lookup discriminator value for Pig. Error message: EXPR must be a length 1 vector. Input: \\{\\}, The JSON input ` \\{\\} ` is invalid for BasquePig: the required field `className` is missing\\., The JSON input ` \\{\\} ` is invalid for DanishPig: the required field `className` is missing\\.') - expect_error(pig$validateJSON('{}'), 'No match found when deserializing the payload into Pig with oneOf schemas BasquePig, DanishPig. Details: Failed to lookup discriminator value for Pig. Error message: EXPR must be a length 1 vector. Input: \\{\\}, The JSON input ` \\{\\} ` is invalid for BasquePig: the required field `className` is missing\\., The JSON input ` \\{\\} ` is invalid for DanishPig: the required field `className` is missing\\.') + expect_error(pig$fromJSON('{}'), 'No match found when deserializing the input into Pig with oneOf schemas BasquePig, DanishPig. Details: >> Failed to lookup discriminator value for Pig. Error message: Error! The value of the discriminator property `className`, which should be the class type, is null. JSON input: \\{\\} >> The JSON input ` \\{\\} ` is invalid for BasquePig: the required field `className` is missing\\. >> The JSON input ` \\{\\} ` is invalid for DanishPig: the required field `className` is missing\\.') + expect_error(pig$validateJSON('{}'), 'No match found when deserializing the input into Pig with oneOf schemas BasquePig, DanishPig. Details: >> Failed to lookup discriminator value for Pig. Error message: Error! The value of the discriminator property `className`, which should be the class type, is null. JSON input: \\{\\} >> The JSON input ` \\{\\} ` is invalid for BasquePig: the required field `className` is missing\\. >> The JSON input ` \\{\\} ` is invalid for DanishPig: the required field `className` is missing\\.') # class name test expect_equal(get(class(basque_pig$actual_instance)[[1]], pos = -1)$classname, "BasquePig") @@ -587,8 +587,8 @@ test_that("Tests anyOf", { expect_equal(basque_pig$toJSONString(), original_basque_pig$toJSONString()) # test exception when no matche found - expect_error(pig$fromJSON('{}'), 'No match found when deserializing the payload into AnyOfPig with anyOf schemas BasquePig, DanishPig. Details: The JSON input ` \\{\\} ` is invalid for BasquePig: the required field `className` is missing\\., The JSON input ` \\{\\} ` is invalid for DanishPig: the required field `className` is missing\\.') - expect_error(pig$validateJSON('{}'), 'No match found when deserializing the payload into AnyOfPig with anyOf schemas BasquePig, DanishPig. Details: The JSON input ` \\{\\} ` is invalid for BasquePig: the required field `className` is missing\\., The JSON input ` \\{\\} ` is invalid for DanishPig: the required field `className` is missing\\.') + expect_error(pig$fromJSON('{}'), 'No match found when deserializing the input into AnyOfPig with anyOf schemas BasquePig, DanishPig. Details: >> The JSON input ` \\{\\} ` is invalid for BasquePig: the required field `className` is missing\\. >> The JSON input ` \\{\\} ` is invalid for DanishPig: the required field `className` is missing\\.') + expect_error(pig$validateJSON('{}'), 'No match found when deserializing the input into AnyOfPig with anyOf schemas BasquePig, DanishPig. Details: >> The JSON input ` \\{\\} ` is invalid for BasquePig: the required field `className` is missing\\. >> The JSON input ` \\{\\} ` is invalid for DanishPig: the required field `className` is missing\\.') }) diff --git a/samples/client/petstore/R-httr2/R/any_of_pig.R b/samples/client/petstore/R-httr2/R/any_of_pig.R index 404b7104727..64e859d560b 100644 --- a/samples/client/petstore/R-httr2/R/any_of_pig.R +++ b/samples/client/petstore/R-httr2/R/any_of_pig.R @@ -90,8 +90,8 @@ AnyOfPig <- R6::R6Class( } # no match - stop(paste("No match found when deserializing the payload into AnyOfPig with anyOf schemas BasquePig, DanishPig. Details: ", - paste(error_messages, collapse = ", "))) + stop(paste("No match found when deserializing the input into AnyOfPig with anyOf schemas BasquePig, DanishPig. Details: >>", + paste(error_messages, collapse = " >> "))) }, #' Serialize AnyOfPig to JSON string. #' diff --git a/samples/client/petstore/R-httr2/R/any_of_primitive_type_test.R b/samples/client/petstore/R-httr2/R/any_of_primitive_type_test.R index 374aa8c6057..da1e53ce472 100644 --- a/samples/client/petstore/R-httr2/R/any_of_primitive_type_test.R +++ b/samples/client/petstore/R-httr2/R/any_of_primitive_type_test.R @@ -102,11 +102,12 @@ AnyOfPrimitiveTypeTest <- R6::R6Class( self$actual_type <- instance_type } else if (matched > 1) { # more than 1 match - stop("Multiple matches found when deserializing the payload into AnyOfPrimitiveTypeTest with oneOf schemas character, integer.") + stop(paste("Multiple matches found when deserializing the input into AnyOfPrimitiveTypeTest with oneOf schemas character, integer. Matched schemas: ", + paste(matched_schemas, collapse = ", "))) } else { # no match - stop(paste("No match found when deserializing the payload into AnyOfPrimitiveTypeTest with oneOf schemas character, integer. Details: ", - paste(error_messages, collapse = ", "))) + stop(paste("No match found when deserializing the input into AnyOfPrimitiveTypeTest with oneOf schemas character, integer. Details: >>", + paste(error_messages, collapse = " >> "))) } self diff --git a/samples/client/petstore/R-httr2/R/mammal.R b/samples/client/petstore/R-httr2/R/mammal.R index 4b21d8564cd..9864432e8fb 100644 --- a/samples/client/petstore/R-httr2/R/mammal.R +++ b/samples/client/petstore/R-httr2/R/mammal.R @@ -100,11 +100,12 @@ Mammal <- R6::R6Class( self$actual_type <- instance_type } else if (matched > 1) { # more than 1 match - stop("Multiple matches found when deserializing the payload into Mammal with oneOf schemas Whale, Zebra.") + stop(paste("Multiple matches found when deserializing the input into Mammal with oneOf schemas Whale, Zebra. Matched schemas: ", + paste(matched_schemas, collapse = ", "))) } else { # no match - stop(paste("No match found when deserializing the payload into Mammal with oneOf schemas Whale, Zebra. Details: ", - paste(error_messages, collapse = ", "))) + stop(paste("No match found when deserializing the input into Mammal with oneOf schemas Whale, Zebra. Details: >>", + paste(error_messages, collapse = " >> "))) } self diff --git a/samples/client/petstore/R-httr2/R/one_of_primitive_type_test.R b/samples/client/petstore/R-httr2/R/one_of_primitive_type_test.R index d558c0eb507..ed13169f902 100644 --- a/samples/client/petstore/R-httr2/R/one_of_primitive_type_test.R +++ b/samples/client/petstore/R-httr2/R/one_of_primitive_type_test.R @@ -102,11 +102,12 @@ OneOfPrimitiveTypeTest <- R6::R6Class( self$actual_type <- instance_type } else if (matched > 1) { # more than 1 match - stop("Multiple matches found when deserializing the payload into OneOfPrimitiveTypeTest with oneOf schemas character, integer.") + stop(paste("Multiple matches found when deserializing the input into OneOfPrimitiveTypeTest with oneOf schemas character, integer. Matched schemas: ", + paste(matched_schemas, collapse = ", "))) } else { # no match - stop(paste("No match found when deserializing the payload into OneOfPrimitiveTypeTest with oneOf schemas character, integer. Details: ", - paste(error_messages, collapse = ", "))) + stop(paste("No match found when deserializing the input into OneOfPrimitiveTypeTest with oneOf schemas character, integer. Details: >>", + paste(error_messages, collapse = " >> "))) } self diff --git a/samples/client/petstore/R-httr2/R/pig.R b/samples/client/petstore/R-httr2/R/pig.R index 6cb6b568abf..570346408f3 100644 --- a/samples/client/petstore/R-httr2/R/pig.R +++ b/samples/client/petstore/R-httr2/R/pig.R @@ -100,11 +100,12 @@ Pig <- R6::R6Class( self$actual_type <- instance_type } else if (matched > 1) { # more than 1 match - stop("Multiple matches found when deserializing the payload into Pig with oneOf schemas BasquePig, DanishPig.") + stop(paste("Multiple matches found when deserializing the input into Pig with oneOf schemas BasquePig, DanishPig. Matched schemas: ", + paste(matched_schemas, collapse = ", "))) } else { # no match - stop(paste("No match found when deserializing the payload into Pig with oneOf schemas BasquePig, DanishPig. Details: ", - paste(error_messages, collapse = ", "))) + stop(paste("No match found when deserializing the input into Pig with oneOf schemas BasquePig, DanishPig. Details: >>", + paste(error_messages, collapse = " >> "))) } self diff --git a/samples/client/petstore/R-httr2/tests/testthat/test_petstore.R b/samples/client/petstore/R-httr2/tests/testthat/test_petstore.R index 73723ba1d63..9e220b9af6d 100644 --- a/samples/client/petstore/R-httr2/tests/testthat/test_petstore.R +++ b/samples/client/petstore/R-httr2/tests/testthat/test_petstore.R @@ -270,7 +270,7 @@ test_that("Tests oneOf primitive types", { expect_equal(test$actual_instance, 456) expect_equal(test$actual_type, 'integer') - expect_error(test$fromJSONString("[45,12]"), "No match found when deserializing the payload into OneOfPrimitiveTypeTest with oneOf schemas character, integer. Details: Data type doesn't match. Expected: integer. Actual: list., Data type doesn't match. Expected: character. Actual: list.") # should throw an error + expect_error(test$fromJSONString("[45,12]"), "No match found when deserializing the input into OneOfPrimitiveTypeTest with oneOf schemas character, integer. Details: >> Data type doesn't match. Expected: integer. Actual: list. >> Data type doesn't match. Expected: character. Actual: list.") # should throw an error }) test_that("Tests anyOf primitive types", { @@ -283,7 +283,7 @@ test_that("Tests anyOf primitive types", { expect_equal(test$actual_instance, 456) expect_equal(test$actual_type, 'integer') - expect_error(test$fromJSONString("[45,12]"), "No match found when deserializing the payload into AnyOfPrimitiveTypeTest with oneOf schemas character, integer. Details: Data type doesn't match. Expected: integer. Actual: list., Data type doesn't match. Expected: character. Actual: list.") # should throw an error + expect_error(test$fromJSONString("[45,12]"), "No match found when deserializing the input into AnyOfPrimitiveTypeTest with oneOf schemas character, integer. Details: >> Data type doesn't match. Expected: integer. Actual: list. >> Data type doesn't match. Expected: character. Actual: list.") # should throw an error }) test_that("Tests oneOf", { @@ -325,8 +325,8 @@ test_that("Tests oneOf", { expect_equal(basque_pig$toJSONString(), original_basque_pig$toJSONString()) # test exception when no matche found - expect_error(pig$fromJSON('{}'), 'No match found when deserializing the payload into Pig with oneOf schemas BasquePig, DanishPig. Details: The JSON input ` \\{\\} ` is invalid for BasquePig: the required field `className` is missing\\., The JSON input ` \\{\\} ` is invalid for DanishPig: the required field `className` is missing\\.') - expect_error(pig$validateJSON('{}'), 'No match found when deserializing the payload into Pig with oneOf schemas BasquePig, DanishPig. Details: The JSON input ` \\{\\} ` is invalid for BasquePig: the required field `className` is missing\\., The JSON input ` \\{\\} ` is invalid for DanishPig: the required field `className` is missing\\.') + expect_error(pig$fromJSON('{}'), 'No match found when deserializing the input into Pig with oneOf schemas BasquePig, DanishPig. Details: >> The JSON input ` \\{\\} ` is invalid for BasquePig: the required field `className` is missing\\. >> The JSON input ` \\{\\} ` is invalid for DanishPig: the required field `className` is missing\\.') + expect_error(pig$validateJSON('{}'), 'No match found when deserializing the input into Pig with oneOf schemas BasquePig, DanishPig. Details: >> The JSON input ` \\{\\} ` is invalid for BasquePig: the required field `className` is missing\\. >> The JSON input ` \\{\\} ` is invalid for DanishPig: the required field `className` is missing\\.') # class name test expect_equal(get(class(basque_pig$actual_instance)[[1]], pos = -1)$classname, "BasquePig") @@ -394,7 +394,7 @@ test_that("Tests anyOf", { expect_equal(basque_pig$toJSONString(), original_basque_pig$toJSONString()) # test exception when no matche found - expect_error(pig$fromJSON('{}'), 'No match found when deserializing the payload into AnyOfPig with anyOf schemas BasquePig, DanishPig. Details: The JSON input ` \\{\\} ` is invalid for BasquePig: the required field `className` is missing\\., The JSON input ` \\{\\} ` is invalid for DanishPig: the required field `className` is missing\\.') - expect_error(pig$validateJSON('{}'), 'No match found when deserializing the payload into AnyOfPig with anyOf schemas BasquePig, DanishPig. Details: The JSON input ` \\{\\} ` is invalid for BasquePig: the required field `className` is missing\\., The JSON input ` \\{\\} ` is invalid for DanishPig: the required field `className` is missing\\.') + expect_error(pig$fromJSON('{}'), 'No match found when deserializing the input into AnyOfPig with anyOf schemas BasquePig, DanishPig. Details: >> The JSON input ` \\{\\} ` is invalid for BasquePig: the required field `className` is missing\\. >> The JSON input ` \\{\\} ` is invalid for DanishPig: the required field `className` is missing\\.') + expect_error(pig$validateJSON('{}'), 'No match found when deserializing the input into AnyOfPig with anyOf schemas BasquePig, DanishPig. Details: >> The JSON input ` \\{\\} ` is invalid for BasquePig: the required field `className` is missing\\. >> The JSON input ` \\{\\} ` is invalid for DanishPig: the required field `className` is missing\\.') }) diff --git a/samples/client/petstore/R/R/any_of_pig.R b/samples/client/petstore/R/R/any_of_pig.R index 404b7104727..64e859d560b 100644 --- a/samples/client/petstore/R/R/any_of_pig.R +++ b/samples/client/petstore/R/R/any_of_pig.R @@ -90,8 +90,8 @@ AnyOfPig <- R6::R6Class( } # no match - stop(paste("No match found when deserializing the payload into AnyOfPig with anyOf schemas BasquePig, DanishPig. Details: ", - paste(error_messages, collapse = ", "))) + stop(paste("No match found when deserializing the input into AnyOfPig with anyOf schemas BasquePig, DanishPig. Details: >>", + paste(error_messages, collapse = " >> "))) }, #' Serialize AnyOfPig to JSON string. #' diff --git a/samples/client/petstore/R/R/any_of_primitive_type_test.R b/samples/client/petstore/R/R/any_of_primitive_type_test.R index 374aa8c6057..da1e53ce472 100644 --- a/samples/client/petstore/R/R/any_of_primitive_type_test.R +++ b/samples/client/petstore/R/R/any_of_primitive_type_test.R @@ -102,11 +102,12 @@ AnyOfPrimitiveTypeTest <- R6::R6Class( self$actual_type <- instance_type } else if (matched > 1) { # more than 1 match - stop("Multiple matches found when deserializing the payload into AnyOfPrimitiveTypeTest with oneOf schemas character, integer.") + stop(paste("Multiple matches found when deserializing the input into AnyOfPrimitiveTypeTest with oneOf schemas character, integer. Matched schemas: ", + paste(matched_schemas, collapse = ", "))) } else { # no match - stop(paste("No match found when deserializing the payload into AnyOfPrimitiveTypeTest with oneOf schemas character, integer. Details: ", - paste(error_messages, collapse = ", "))) + stop(paste("No match found when deserializing the input into AnyOfPrimitiveTypeTest with oneOf schemas character, integer. Details: >>", + paste(error_messages, collapse = " >> "))) } self diff --git a/samples/client/petstore/R/R/mammal.R b/samples/client/petstore/R/R/mammal.R index 4b21d8564cd..9864432e8fb 100644 --- a/samples/client/petstore/R/R/mammal.R +++ b/samples/client/petstore/R/R/mammal.R @@ -100,11 +100,12 @@ Mammal <- R6::R6Class( self$actual_type <- instance_type } else if (matched > 1) { # more than 1 match - stop("Multiple matches found when deserializing the payload into Mammal with oneOf schemas Whale, Zebra.") + stop(paste("Multiple matches found when deserializing the input into Mammal with oneOf schemas Whale, Zebra. Matched schemas: ", + paste(matched_schemas, collapse = ", "))) } else { # no match - stop(paste("No match found when deserializing the payload into Mammal with oneOf schemas Whale, Zebra. Details: ", - paste(error_messages, collapse = ", "))) + stop(paste("No match found when deserializing the input into Mammal with oneOf schemas Whale, Zebra. Details: >>", + paste(error_messages, collapse = " >> "))) } self diff --git a/samples/client/petstore/R/R/one_of_primitive_type_test.R b/samples/client/petstore/R/R/one_of_primitive_type_test.R index d558c0eb507..ed13169f902 100644 --- a/samples/client/petstore/R/R/one_of_primitive_type_test.R +++ b/samples/client/petstore/R/R/one_of_primitive_type_test.R @@ -102,11 +102,12 @@ OneOfPrimitiveTypeTest <- R6::R6Class( self$actual_type <- instance_type } else if (matched > 1) { # more than 1 match - stop("Multiple matches found when deserializing the payload into OneOfPrimitiveTypeTest with oneOf schemas character, integer.") + stop(paste("Multiple matches found when deserializing the input into OneOfPrimitiveTypeTest with oneOf schemas character, integer. Matched schemas: ", + paste(matched_schemas, collapse = ", "))) } else { # no match - stop(paste("No match found when deserializing the payload into OneOfPrimitiveTypeTest with oneOf schemas character, integer. Details: ", - paste(error_messages, collapse = ", "))) + stop(paste("No match found when deserializing the input into OneOfPrimitiveTypeTest with oneOf schemas character, integer. Details: >>", + paste(error_messages, collapse = " >> "))) } self diff --git a/samples/client/petstore/R/R/pig.R b/samples/client/petstore/R/R/pig.R index 6cb6b568abf..570346408f3 100644 --- a/samples/client/petstore/R/R/pig.R +++ b/samples/client/petstore/R/R/pig.R @@ -100,11 +100,12 @@ Pig <- R6::R6Class( self$actual_type <- instance_type } else if (matched > 1) { # more than 1 match - stop("Multiple matches found when deserializing the payload into Pig with oneOf schemas BasquePig, DanishPig.") + stop(paste("Multiple matches found when deserializing the input into Pig with oneOf schemas BasquePig, DanishPig. Matched schemas: ", + paste(matched_schemas, collapse = ", "))) } else { # no match - stop(paste("No match found when deserializing the payload into Pig with oneOf schemas BasquePig, DanishPig. Details: ", - paste(error_messages, collapse = ", "))) + stop(paste("No match found when deserializing the input into Pig with oneOf schemas BasquePig, DanishPig. Details: >>", + paste(error_messages, collapse = " >> "))) } self diff --git a/samples/client/petstore/R/tests/testthat/test_petstore.R b/samples/client/petstore/R/tests/testthat/test_petstore.R index 4a205dd2006..aee591b5256 100644 --- a/samples/client/petstore/R/tests/testthat/test_petstore.R +++ b/samples/client/petstore/R/tests/testthat/test_petstore.R @@ -259,8 +259,8 @@ test_that("Tests oneOf", { expect_equal(basque_pig$toJSONString(), original_basque_pig$toJSONString()) # test exception when no matche found - expect_error(pig$fromJSON('{}'), 'No match found when deserializing the payload into Pig with oneOf schemas BasquePig, DanishPig. Details: The JSON input ` \\{\\} ` is invalid for BasquePig: the required field `className` is missing\\., The JSON input ` \\{\\} ` is invalid for DanishPig: the required field `className` is missing\\.') - expect_error(pig$validateJSON('{}'), 'No match found when deserializing the payload into Pig with oneOf schemas BasquePig, DanishPig. Details: The JSON input ` \\{\\} ` is invalid for BasquePig: the required field `className` is missing\\., The JSON input ` \\{\\} ` is invalid for DanishPig: the required field `className` is missing\\.') + expect_error(pig$fromJSON('{}'), 'No match found when deserializing the input into Pig with oneOf schemas BasquePig, DanishPig. Details: >> The JSON input ` \\{\\} ` is invalid for BasquePig: the required field `className` is missing\\. >> The JSON input ` \\{\\} ` is invalid for DanishPig: the required field `className` is missing\\.') + expect_error(pig$validateJSON('{}'), 'No match found when deserializing the input into Pig with oneOf schemas BasquePig, DanishPig. Details: >> The JSON input ` \\{\\} ` is invalid for BasquePig: the required field `className` is missing\\. >> The JSON input ` \\{\\} ` is invalid for DanishPig: the required field `className` is missing\\.') # class name test expect_equal(get(class(basque_pig$actual_instance)[[1]], pos = -1)$classname, "BasquePig") @@ -328,8 +328,8 @@ test_that("Tests anyOf", { expect_equal(basque_pig$toJSONString(), original_basque_pig$toJSONString()) # test exception when no matche found - expect_error(pig$fromJSON('{}'), 'No match found when deserializing the payload into AnyOfPig with anyOf schemas BasquePig, DanishPig. Details: The JSON input ` \\{\\} ` is invalid for BasquePig: the required field `className` is missing\\., The JSON input ` \\{\\} ` is invalid for DanishPig: the required field `className` is missing\\.') - expect_error(pig$validateJSON('{}'), 'No match found when deserializing the payload into AnyOfPig with anyOf schemas BasquePig, DanishPig. Details: The JSON input ` \\{\\} ` is invalid for BasquePig: the required field `className` is missing\\., The JSON input ` \\{\\} ` is invalid for DanishPig: the required field `className` is missing\\.') + expect_error(pig$fromJSON('{}'), 'No match found when deserializing the input into AnyOfPig with anyOf schemas BasquePig, DanishPig. Details: >> The JSON input ` \\{\\} ` is invalid for BasquePig: the required field `className` is missing\\. >> The JSON input ` \\{\\} ` is invalid for DanishPig: the required field `className` is missing\\.') + expect_error(pig$validateJSON('{}'), 'No match found when deserializing the input into AnyOfPig with anyOf schemas BasquePig, DanishPig. Details: >> The JSON input ` \\{\\} ` is invalid for BasquePig: the required field `className` is missing\\. >> The JSON input ` \\{\\} ` is invalid for DanishPig: the required field `className` is missing\\.') })