forked from loafle/openapi-generator-original
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
This commit is contained in:
parent
b35ea31e82
commit
363906fda3
@ -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.
|
||||
#'
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
#'
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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\\.')
|
||||
|
||||
})
|
||||
|
||||
|
@ -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.
|
||||
#'
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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\\.')
|
||||
|
||||
})
|
||||
|
@ -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.
|
||||
#'
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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\\.')
|
||||
|
||||
})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user