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}}
|
{{/isNull}}
|
||||||
{{/composedSchemas.anyOf}}
|
{{/composedSchemas.anyOf}}
|
||||||
# no match
|
# no match
|
||||||
stop(paste("No match found when deserializing the payload into {{{classname}}} with anyOf schemas {{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}. Details: ",
|
stop(paste("No match found when deserializing the input into {{{classname}}} with anyOf schemas {{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}. Details: >>",
|
||||||
paste(error_messages, collapse = ", ")))
|
paste(error_messages, collapse = " >> ")))
|
||||||
},
|
},
|
||||||
#' Serialize {{{classname}}} to JSON string.
|
#' Serialize {{{classname}}} to JSON string.
|
||||||
#'
|
#'
|
||||||
|
@ -65,6 +65,9 @@
|
|||||||
{{#discriminator}}
|
{{#discriminator}}
|
||||||
oneof_lookup_result <- tryCatch({
|
oneof_lookup_result <- tryCatch({
|
||||||
discriminatorValue <- (jsonlite::fromJSON(input, simplifyVector = FALSE))$`{{{propertyBaseName}}}`
|
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,
|
switch(discriminatorValue,
|
||||||
{{#mappedModels}}
|
{{#mappedModels}}
|
||||||
{{{mappingName}}}={
|
{{{mappingName}}}={
|
||||||
@ -89,7 +92,7 @@
|
|||||||
error = function(err) err
|
error = function(err) err
|
||||||
)
|
)
|
||||||
if (!is.null(oneof_lookup_result["error"])) {
|
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}}
|
{{/discriminator}}
|
||||||
@ -127,11 +130,12 @@
|
|||||||
self$actual_type <- instance_type
|
self$actual_type <- instance_type
|
||||||
} else if (matched > 1) {
|
} else if (matched > 1) {
|
||||||
# more than 1 match
|
# 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 {
|
} else {
|
||||||
# no match
|
# no match
|
||||||
stop(paste("No match found when deserializing the payload into {{{classname}}} with oneOf schemas {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}. Details: ",
|
stop(paste("No match found when deserializing the input into {{{classname}}} with oneOf schemas {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}. Details: >>",
|
||||||
paste(error_messages, collapse = ", ")))
|
paste(error_messages, collapse = " >> ")))
|
||||||
}
|
}
|
||||||
|
|
||||||
self
|
self
|
||||||
|
@ -90,8 +90,8 @@ AnyOfPig <- R6::R6Class(
|
|||||||
}
|
}
|
||||||
|
|
||||||
# no match
|
# no match
|
||||||
stop(paste("No match found when deserializing the payload into AnyOfPig with anyOf schemas BasquePig, DanishPig. Details: ",
|
stop(paste("No match found when deserializing the input into AnyOfPig with anyOf schemas BasquePig, DanishPig. Details: >>",
|
||||||
paste(error_messages, collapse = ", ")))
|
paste(error_messages, collapse = " >> ")))
|
||||||
},
|
},
|
||||||
#' Serialize AnyOfPig to JSON string.
|
#' Serialize AnyOfPig to JSON string.
|
||||||
#'
|
#'
|
||||||
|
@ -102,11 +102,12 @@ AnyOfPrimitiveTypeTest <- R6::R6Class(
|
|||||||
self$actual_type <- instance_type
|
self$actual_type <- instance_type
|
||||||
} else if (matched > 1) {
|
} else if (matched > 1) {
|
||||||
# more than 1 match
|
# 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 {
|
} else {
|
||||||
# no match
|
# no match
|
||||||
stop(paste("No match found when deserializing the payload into AnyOfPrimitiveTypeTest with oneOf schemas character, integer. Details: ",
|
stop(paste("No match found when deserializing the input into AnyOfPrimitiveTypeTest with oneOf schemas character, integer. Details: >>",
|
||||||
paste(error_messages, collapse = ", ")))
|
paste(error_messages, collapse = " >> ")))
|
||||||
}
|
}
|
||||||
|
|
||||||
self
|
self
|
||||||
|
@ -66,6 +66,9 @@ Mammal <- R6::R6Class(
|
|||||||
|
|
||||||
oneof_lookup_result <- tryCatch({
|
oneof_lookup_result <- tryCatch({
|
||||||
discriminatorValue <- (jsonlite::fromJSON(input, simplifyVector = FALSE))$`className`
|
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,
|
switch(discriminatorValue,
|
||||||
whale={
|
whale={
|
||||||
Whale$public_methods$validateJSON(input)
|
Whale$public_methods$validateJSON(input)
|
||||||
@ -84,7 +87,7 @@ Mammal <- R6::R6Class(
|
|||||||
error = function(err) err
|
error = function(err) err
|
||||||
)
|
)
|
||||||
if (!is.null(oneof_lookup_result["error"])) {
|
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({
|
Whale_result <- tryCatch({
|
||||||
@ -123,11 +126,12 @@ Mammal <- R6::R6Class(
|
|||||||
self$actual_type <- instance_type
|
self$actual_type <- instance_type
|
||||||
} else if (matched > 1) {
|
} else if (matched > 1) {
|
||||||
# more than 1 match
|
# 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 {
|
} else {
|
||||||
# no match
|
# no match
|
||||||
stop(paste("No match found when deserializing the payload into Mammal with oneOf schemas Whale, Zebra. Details: ",
|
stop(paste("No match found when deserializing the input into Mammal with oneOf schemas Whale, Zebra. Details: >>",
|
||||||
paste(error_messages, collapse = ", ")))
|
paste(error_messages, collapse = " >> ")))
|
||||||
}
|
}
|
||||||
|
|
||||||
self
|
self
|
||||||
|
@ -102,11 +102,12 @@ OneOfPrimitiveTypeTest <- R6::R6Class(
|
|||||||
self$actual_type <- instance_type
|
self$actual_type <- instance_type
|
||||||
} else if (matched > 1) {
|
} else if (matched > 1) {
|
||||||
# more than 1 match
|
# 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 {
|
} else {
|
||||||
# no match
|
# no match
|
||||||
stop(paste("No match found when deserializing the payload into OneOfPrimitiveTypeTest with oneOf schemas character, integer. Details: ",
|
stop(paste("No match found when deserializing the input into OneOfPrimitiveTypeTest with oneOf schemas character, integer. Details: >>",
|
||||||
paste(error_messages, collapse = ", ")))
|
paste(error_messages, collapse = " >> ")))
|
||||||
}
|
}
|
||||||
|
|
||||||
self
|
self
|
||||||
|
@ -66,6 +66,9 @@ Pig <- R6::R6Class(
|
|||||||
|
|
||||||
oneof_lookup_result <- tryCatch({
|
oneof_lookup_result <- tryCatch({
|
||||||
discriminatorValue <- (jsonlite::fromJSON(input, simplifyVector = FALSE))$`className`
|
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,
|
switch(discriminatorValue,
|
||||||
BasquePig={
|
BasquePig={
|
||||||
BasquePig$public_methods$validateJSON(input)
|
BasquePig$public_methods$validateJSON(input)
|
||||||
@ -84,7 +87,7 @@ Pig <- R6::R6Class(
|
|||||||
error = function(err) err
|
error = function(err) err
|
||||||
)
|
)
|
||||||
if (!is.null(oneof_lookup_result["error"])) {
|
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({
|
BasquePig_result <- tryCatch({
|
||||||
@ -123,11 +126,12 @@ Pig <- R6::R6Class(
|
|||||||
self$actual_type <- instance_type
|
self$actual_type <- instance_type
|
||||||
} else if (matched > 1) {
|
} else if (matched > 1) {
|
||||||
# more than 1 match
|
# 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 {
|
} else {
|
||||||
# no match
|
# no match
|
||||||
stop(paste("No match found when deserializing the payload into Pig with oneOf schemas BasquePig, DanishPig. Details: ",
|
stop(paste("No match found when deserializing the input into Pig with oneOf schemas BasquePig, DanishPig. Details: >>",
|
||||||
paste(error_messages, collapse = ", ")))
|
paste(error_messages, collapse = " >> ")))
|
||||||
}
|
}
|
||||||
|
|
||||||
self
|
self
|
||||||
|
@ -518,8 +518,8 @@ test_that("Tests oneOf", {
|
|||||||
expect_equal(basque_pig$toJSONString(), original_basque_pig$toJSONString())
|
expect_equal(basque_pig$toJSONString(), original_basque_pig$toJSONString())
|
||||||
|
|
||||||
# test exception when no matche found
|
# 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$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 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 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
|
# class name test
|
||||||
expect_equal(get(class(basque_pig$actual_instance)[[1]], pos = -1)$classname, "BasquePig")
|
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())
|
expect_equal(basque_pig$toJSONString(), original_basque_pig$toJSONString())
|
||||||
|
|
||||||
# test exception when no matche found
|
# 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$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 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 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
|
# no match
|
||||||
stop(paste("No match found when deserializing the payload into AnyOfPig with anyOf schemas BasquePig, DanishPig. Details: ",
|
stop(paste("No match found when deserializing the input into AnyOfPig with anyOf schemas BasquePig, DanishPig. Details: >>",
|
||||||
paste(error_messages, collapse = ", ")))
|
paste(error_messages, collapse = " >> ")))
|
||||||
},
|
},
|
||||||
#' Serialize AnyOfPig to JSON string.
|
#' Serialize AnyOfPig to JSON string.
|
||||||
#'
|
#'
|
||||||
|
@ -102,11 +102,12 @@ AnyOfPrimitiveTypeTest <- R6::R6Class(
|
|||||||
self$actual_type <- instance_type
|
self$actual_type <- instance_type
|
||||||
} else if (matched > 1) {
|
} else if (matched > 1) {
|
||||||
# more than 1 match
|
# 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 {
|
} else {
|
||||||
# no match
|
# no match
|
||||||
stop(paste("No match found when deserializing the payload into AnyOfPrimitiveTypeTest with oneOf schemas character, integer. Details: ",
|
stop(paste("No match found when deserializing the input into AnyOfPrimitiveTypeTest with oneOf schemas character, integer. Details: >>",
|
||||||
paste(error_messages, collapse = ", ")))
|
paste(error_messages, collapse = " >> ")))
|
||||||
}
|
}
|
||||||
|
|
||||||
self
|
self
|
||||||
|
@ -100,11 +100,12 @@ Mammal <- R6::R6Class(
|
|||||||
self$actual_type <- instance_type
|
self$actual_type <- instance_type
|
||||||
} else if (matched > 1) {
|
} else if (matched > 1) {
|
||||||
# more than 1 match
|
# 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 {
|
} else {
|
||||||
# no match
|
# no match
|
||||||
stop(paste("No match found when deserializing the payload into Mammal with oneOf schemas Whale, Zebra. Details: ",
|
stop(paste("No match found when deserializing the input into Mammal with oneOf schemas Whale, Zebra. Details: >>",
|
||||||
paste(error_messages, collapse = ", ")))
|
paste(error_messages, collapse = " >> ")))
|
||||||
}
|
}
|
||||||
|
|
||||||
self
|
self
|
||||||
|
@ -102,11 +102,12 @@ OneOfPrimitiveTypeTest <- R6::R6Class(
|
|||||||
self$actual_type <- instance_type
|
self$actual_type <- instance_type
|
||||||
} else if (matched > 1) {
|
} else if (matched > 1) {
|
||||||
# more than 1 match
|
# 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 {
|
} else {
|
||||||
# no match
|
# no match
|
||||||
stop(paste("No match found when deserializing the payload into OneOfPrimitiveTypeTest with oneOf schemas character, integer. Details: ",
|
stop(paste("No match found when deserializing the input into OneOfPrimitiveTypeTest with oneOf schemas character, integer. Details: >>",
|
||||||
paste(error_messages, collapse = ", ")))
|
paste(error_messages, collapse = " >> ")))
|
||||||
}
|
}
|
||||||
|
|
||||||
self
|
self
|
||||||
|
@ -100,11 +100,12 @@ Pig <- R6::R6Class(
|
|||||||
self$actual_type <- instance_type
|
self$actual_type <- instance_type
|
||||||
} else if (matched > 1) {
|
} else if (matched > 1) {
|
||||||
# more than 1 match
|
# 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 {
|
} else {
|
||||||
# no match
|
# no match
|
||||||
stop(paste("No match found when deserializing the payload into Pig with oneOf schemas BasquePig, DanishPig. Details: ",
|
stop(paste("No match found when deserializing the input into Pig with oneOf schemas BasquePig, DanishPig. Details: >>",
|
||||||
paste(error_messages, collapse = ", ")))
|
paste(error_messages, collapse = " >> ")))
|
||||||
}
|
}
|
||||||
|
|
||||||
self
|
self
|
||||||
|
@ -270,7 +270,7 @@ test_that("Tests oneOf primitive types", {
|
|||||||
expect_equal(test$actual_instance, 456)
|
expect_equal(test$actual_instance, 456)
|
||||||
expect_equal(test$actual_type, 'integer')
|
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", {
|
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_instance, 456)
|
||||||
expect_equal(test$actual_type, 'integer')
|
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", {
|
test_that("Tests oneOf", {
|
||||||
@ -325,8 +325,8 @@ test_that("Tests oneOf", {
|
|||||||
expect_equal(basque_pig$toJSONString(), original_basque_pig$toJSONString())
|
expect_equal(basque_pig$toJSONString(), original_basque_pig$toJSONString())
|
||||||
|
|
||||||
# test exception when no matche found
|
# 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$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 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 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
|
# class name test
|
||||||
expect_equal(get(class(basque_pig$actual_instance)[[1]], pos = -1)$classname, "BasquePig")
|
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())
|
expect_equal(basque_pig$toJSONString(), original_basque_pig$toJSONString())
|
||||||
|
|
||||||
# test exception when no matche found
|
# 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$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 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 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
|
# no match
|
||||||
stop(paste("No match found when deserializing the payload into AnyOfPig with anyOf schemas BasquePig, DanishPig. Details: ",
|
stop(paste("No match found when deserializing the input into AnyOfPig with anyOf schemas BasquePig, DanishPig. Details: >>",
|
||||||
paste(error_messages, collapse = ", ")))
|
paste(error_messages, collapse = " >> ")))
|
||||||
},
|
},
|
||||||
#' Serialize AnyOfPig to JSON string.
|
#' Serialize AnyOfPig to JSON string.
|
||||||
#'
|
#'
|
||||||
|
@ -102,11 +102,12 @@ AnyOfPrimitiveTypeTest <- R6::R6Class(
|
|||||||
self$actual_type <- instance_type
|
self$actual_type <- instance_type
|
||||||
} else if (matched > 1) {
|
} else if (matched > 1) {
|
||||||
# more than 1 match
|
# 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 {
|
} else {
|
||||||
# no match
|
# no match
|
||||||
stop(paste("No match found when deserializing the payload into AnyOfPrimitiveTypeTest with oneOf schemas character, integer. Details: ",
|
stop(paste("No match found when deserializing the input into AnyOfPrimitiveTypeTest with oneOf schemas character, integer. Details: >>",
|
||||||
paste(error_messages, collapse = ", ")))
|
paste(error_messages, collapse = " >> ")))
|
||||||
}
|
}
|
||||||
|
|
||||||
self
|
self
|
||||||
|
@ -100,11 +100,12 @@ Mammal <- R6::R6Class(
|
|||||||
self$actual_type <- instance_type
|
self$actual_type <- instance_type
|
||||||
} else if (matched > 1) {
|
} else if (matched > 1) {
|
||||||
# more than 1 match
|
# 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 {
|
} else {
|
||||||
# no match
|
# no match
|
||||||
stop(paste("No match found when deserializing the payload into Mammal with oneOf schemas Whale, Zebra. Details: ",
|
stop(paste("No match found when deserializing the input into Mammal with oneOf schemas Whale, Zebra. Details: >>",
|
||||||
paste(error_messages, collapse = ", ")))
|
paste(error_messages, collapse = " >> ")))
|
||||||
}
|
}
|
||||||
|
|
||||||
self
|
self
|
||||||
|
@ -102,11 +102,12 @@ OneOfPrimitiveTypeTest <- R6::R6Class(
|
|||||||
self$actual_type <- instance_type
|
self$actual_type <- instance_type
|
||||||
} else if (matched > 1) {
|
} else if (matched > 1) {
|
||||||
# more than 1 match
|
# 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 {
|
} else {
|
||||||
# no match
|
# no match
|
||||||
stop(paste("No match found when deserializing the payload into OneOfPrimitiveTypeTest with oneOf schemas character, integer. Details: ",
|
stop(paste("No match found when deserializing the input into OneOfPrimitiveTypeTest with oneOf schemas character, integer. Details: >>",
|
||||||
paste(error_messages, collapse = ", ")))
|
paste(error_messages, collapse = " >> ")))
|
||||||
}
|
}
|
||||||
|
|
||||||
self
|
self
|
||||||
|
@ -100,11 +100,12 @@ Pig <- R6::R6Class(
|
|||||||
self$actual_type <- instance_type
|
self$actual_type <- instance_type
|
||||||
} else if (matched > 1) {
|
} else if (matched > 1) {
|
||||||
# more than 1 match
|
# 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 {
|
} else {
|
||||||
# no match
|
# no match
|
||||||
stop(paste("No match found when deserializing the payload into Pig with oneOf schemas BasquePig, DanishPig. Details: ",
|
stop(paste("No match found when deserializing the input into Pig with oneOf schemas BasquePig, DanishPig. Details: >>",
|
||||||
paste(error_messages, collapse = ", ")))
|
paste(error_messages, collapse = " >> ")))
|
||||||
}
|
}
|
||||||
|
|
||||||
self
|
self
|
||||||
|
@ -259,8 +259,8 @@ test_that("Tests oneOf", {
|
|||||||
expect_equal(basque_pig$toJSONString(), original_basque_pig$toJSONString())
|
expect_equal(basque_pig$toJSONString(), original_basque_pig$toJSONString())
|
||||||
|
|
||||||
# test exception when no matche found
|
# 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$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 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 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
|
# class name test
|
||||||
expect_equal(get(class(basque_pig$actual_instance)[[1]], pos = -1)$classname, "BasquePig")
|
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())
|
expect_equal(basque_pig$toJSONString(), original_basque_pig$toJSONString())
|
||||||
|
|
||||||
# test exception when no matche found
|
# 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$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 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 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