forked from loafle/openapi-generator-original
[R] Add validateJSON to oneOf, anyOf models (#12548)
* add validateJSON to r oneof, anyof models * update tests
This commit is contained in:
parent
5462681348
commit
14aef2c93d
@ -47,6 +47,18 @@
|
|||||||
} else {
|
} else {
|
||||||
NULL
|
NULL
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
validateJSON = function(input) {
|
||||||
|
# backup current values
|
||||||
|
actual_instance_bak <- self$actual_instance
|
||||||
|
actual_type_bak <- self$actual_type
|
||||||
|
|
||||||
|
# if it's not valid, an error will be thrown
|
||||||
|
self$fromJSON(input)
|
||||||
|
|
||||||
|
# no error thrown, restore old values
|
||||||
|
self$actual_instance <- actual_instance_bak
|
||||||
|
self$actual_type <- actual_type_bak
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -62,6 +62,18 @@
|
|||||||
} else {
|
} else {
|
||||||
NULL
|
NULL
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
validateJSON = function(input) {
|
||||||
|
# backup current values
|
||||||
|
actual_instance_bak <- self$actual_instance
|
||||||
|
actual_type_bak <- self$actual_type
|
||||||
|
|
||||||
|
# if it's not valid, an error will be thrown
|
||||||
|
self$fromJSON(input)
|
||||||
|
|
||||||
|
# no error thrown, restore old values
|
||||||
|
self$actual_instance <- actual_instance_bak
|
||||||
|
self$actual_type <- actual_type_bak
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -66,6 +66,18 @@ AnyOfPig <- R6::R6Class(
|
|||||||
} else {
|
} else {
|
||||||
NULL
|
NULL
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
validateJSON = function(input) {
|
||||||
|
# backup current values
|
||||||
|
actual_instance_bak <- self$actual_instance
|
||||||
|
actual_type_bak <- self$actual_type
|
||||||
|
|
||||||
|
# if it's not valid, an error will be thrown
|
||||||
|
self$fromJSON(input)
|
||||||
|
|
||||||
|
# no error thrown, restore old values
|
||||||
|
self$actual_instance <- actual_instance_bak
|
||||||
|
self$actual_type <- actual_type_bak
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -82,6 +82,18 @@ Pig <- R6::R6Class(
|
|||||||
} else {
|
} else {
|
||||||
NULL
|
NULL
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
validateJSON = function(input) {
|
||||||
|
# backup current values
|
||||||
|
actual_instance_bak <- self$actual_instance
|
||||||
|
actual_type_bak <- self$actual_type
|
||||||
|
|
||||||
|
# if it's not valid, an error will be thrown
|
||||||
|
self$fromJSON(input)
|
||||||
|
|
||||||
|
# no error thrown, restore old values
|
||||||
|
self$actual_instance <- actual_instance_bak
|
||||||
|
self$actual_type <- actual_type_bak
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -159,6 +159,7 @@ test_that("Tests oneOf", {
|
|||||||
# test fromJSON, actual_tpye, actual_instance
|
# test fromJSON, actual_tpye, actual_instance
|
||||||
pig <- Pig$new()
|
pig <- Pig$new()
|
||||||
danish_pig <- pig$fromJSON(danish_pig_json)
|
danish_pig <- pig$fromJSON(danish_pig_json)
|
||||||
|
pig$validateJSON(basque_pig_json) # validate JSON to ensure its actual_instance, actual_type are not updated
|
||||||
expect_equal(danish_pig$actual_type, "DanishPig")
|
expect_equal(danish_pig$actual_type, "DanishPig")
|
||||||
expect_equal(danish_pig$actual_instance$size, 7)
|
expect_equal(danish_pig$actual_instance$size, 7)
|
||||||
expect_equal(danish_pig$actual_instance$className, "DanishPig")
|
expect_equal(danish_pig$actual_instance$className, "DanishPig")
|
||||||
@ -178,7 +179,7 @@ test_that("Tests oneOf", {
|
|||||||
|
|
||||||
# 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 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\\.')
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -221,7 +222,7 @@ test_that("Tests anyOf", {
|
|||||||
|
|
||||||
# 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 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\\.')
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user