mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-04 06:30:52 +00:00
add oneOf discriminator lookup support (#13301)
This commit is contained in:
parent
a582c38aa1
commit
b55fa261f3
@ -12,3 +12,4 @@ additionalProperties:
|
||||
errorObjectType: "ModelApiResponse"
|
||||
operationIdNaming: snake_case
|
||||
generateWrapper: true
|
||||
useOneOfDiscriminatorLookup: true
|
||||
|
@ -76,6 +76,7 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String errorObjectType;
|
||||
protected String operationIdNaming;
|
||||
protected boolean generateWrapper;
|
||||
protected boolean useOneOfDiscriminatorLookup = false; // use oneOf discriminator's mapping for model lookup
|
||||
|
||||
private Map<String, String> schemaKeyToModelNameCache = new HashMap<>();
|
||||
|
||||
@ -265,6 +266,12 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
this.setGenerateWrapper(false);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP)) {
|
||||
setUseOneOfDiscriminatorLookup(convertPropertyToBooleanAndWriteBack(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP));
|
||||
} else {
|
||||
additionalProperties.put(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP, useOneOfDiscriminatorLookup);
|
||||
}
|
||||
|
||||
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
|
||||
additionalProperties.put(CodegenConstants.PACKAGE_VERSION, packageVersion);
|
||||
additionalProperties.put(CodegenConstants.EXCEPTION_ON_FAILURE, returnExceptionOnFailure);
|
||||
@ -623,6 +630,14 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
this.generateWrapper = generateWrapper;
|
||||
}
|
||||
|
||||
public void setUseOneOfDiscriminatorLookup(boolean useOneOfDiscriminatorLookup) {
|
||||
this.useOneOfDiscriminatorLookup = useOneOfDiscriminatorLookup;
|
||||
}
|
||||
|
||||
public boolean getUseOneOfDiscriminatorLookup() {
|
||||
return this.useOneOfDiscriminatorLookup;
|
||||
}
|
||||
|
||||
public void setOperationIdNaming(final String operationIdNaming) {
|
||||
if (!("PascalCase".equals(operationIdNaming) || "camelCase".equals(operationIdNaming) ||
|
||||
"snake_case".equals(operationIdNaming))) {
|
||||
|
@ -61,6 +61,39 @@
|
||||
error_messages <- list()
|
||||
instance <- NULL
|
||||
|
||||
{{#useOneOfDiscriminatorLookup}}
|
||||
{{#discriminator}}
|
||||
oneof_lookup_result <- tryCatch({
|
||||
discriminatorValue <- (jsonlite::fromJSON(input, simplifyVector = FALSE))$`{{{propertyBaseName}}}`
|
||||
switch(discriminatorValue,
|
||||
{{#mappedModels}}
|
||||
{{{mappingName}}}={
|
||||
{{{modelName}}}$public_methods$validateJSON(input)
|
||||
{{{modelName}}}_instance <- {{{modelName}}}$new()
|
||||
self$actual_instance <- {{{modelName}}}_instance$fromJSON(input)
|
||||
self$actual_type <- "{{{modelName}}}"
|
||||
return(self)
|
||||
}{{^-last}},{{/-last}}{{#-last}})},{{/-last}}
|
||||
{{/mappedModels}}
|
||||
{{^mappedModels}}
|
||||
{{#oneOf}}
|
||||
{{{.}}}={
|
||||
{{{.}}}$public_methods$validateJSON(input)
|
||||
{{{.}}}_instance <- {{{.}}}$new()
|
||||
self$actual_instance <- {{{.}}}_instance$fromJSON(input)
|
||||
self$actual_type <- "{{{.}}}"
|
||||
return(self)
|
||||
}{{^-last}},{{/-last}}{{#-last}})},{{/-last}}
|
||||
{{/oneOf}}
|
||||
{{/mappedModels}}
|
||||
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))
|
||||
}
|
||||
|
||||
{{/discriminator}}
|
||||
{{/useOneOfDiscriminatorLookup}}
|
||||
{{#composedSchemas.oneOf}}
|
||||
{{^isNull}}
|
||||
{{{dataType}}}_result <- tryCatch({
|
||||
|
@ -933,14 +933,6 @@ components:
|
||||
- $ref: '#/components/schemas/DanishPig'
|
||||
discriminator:
|
||||
propertyName: className
|
||||
OneOfPrimitiveTypeTest:
|
||||
oneOf:
|
||||
- type: "integer"
|
||||
- type: "string"
|
||||
AnyOfPrimitiveTypeTest:
|
||||
oneOf:
|
||||
- type: "integer"
|
||||
- type: "string"
|
||||
BasquePig:
|
||||
type: object
|
||||
properties:
|
||||
@ -968,3 +960,44 @@ components:
|
||||
type: integer
|
||||
nested_pig:
|
||||
$ref: '#/components/schemas/Pig'
|
||||
OneOfPrimitiveTypeTest:
|
||||
oneOf:
|
||||
- type: "integer"
|
||||
- type: "string"
|
||||
AnyOfPrimitiveTypeTest:
|
||||
oneOf:
|
||||
- type: "integer"
|
||||
- type: "string"
|
||||
mammal:
|
||||
oneOf:
|
||||
- $ref: '#/components/schemas/whale'
|
||||
- $ref: '#/components/schemas/zebra'
|
||||
discriminator:
|
||||
propertyName: className
|
||||
mapping:
|
||||
whale: '#/components/schemas/whale'
|
||||
zebra: '#/components/schemas/zebra'
|
||||
whale:
|
||||
type: object
|
||||
properties:
|
||||
hasBaleen:
|
||||
type: boolean
|
||||
hasTeeth:
|
||||
type: boolean
|
||||
className:
|
||||
type: string
|
||||
required:
|
||||
- className
|
||||
zebra:
|
||||
type: object
|
||||
properties:
|
||||
type:
|
||||
type: string
|
||||
enum:
|
||||
- plains
|
||||
- mountain
|
||||
- grevys
|
||||
className:
|
||||
type: string
|
||||
required:
|
||||
- className
|
||||
|
@ -20,6 +20,7 @@ R/danish_pig.R
|
||||
R/dog.R
|
||||
R/dog_all_of.R
|
||||
R/fake_api.R
|
||||
R/mammal.R
|
||||
R/model_api_response.R
|
||||
R/nested_one_of.R
|
||||
R/one_of_primitive_type_test.R
|
||||
@ -34,6 +35,8 @@ R/tag.R
|
||||
R/update_pet_request.R
|
||||
R/user.R
|
||||
R/user_api.R
|
||||
R/whale.R
|
||||
R/zebra.R
|
||||
README.md
|
||||
docs/AllofTagApiResponse.md
|
||||
docs/Animal.md
|
||||
@ -47,6 +50,7 @@ docs/DanishPig.md
|
||||
docs/Dog.md
|
||||
docs/DogAllOf.md
|
||||
docs/FakeApi.md
|
||||
docs/Mammal.md
|
||||
docs/ModelApiResponse.md
|
||||
docs/NestedOneOf.md
|
||||
docs/OneOfPrimitiveTypeTest.md
|
||||
@ -60,5 +64,7 @@ docs/Tag.md
|
||||
docs/UpdatePetRequest.md
|
||||
docs/User.md
|
||||
docs/UserApi.md
|
||||
docs/Whale.md
|
||||
docs/Zebra.md
|
||||
git_push.sh
|
||||
tests/testthat.R
|
||||
|
@ -27,6 +27,7 @@ export(Category)
|
||||
export(DanishPig)
|
||||
export(Dog)
|
||||
export(DogAllOf)
|
||||
export(Mammal)
|
||||
export(ModelApiResponse)
|
||||
export(NestedOneOf)
|
||||
export(OneOfPrimitiveTypeTest)
|
||||
@ -37,6 +38,8 @@ export(Special)
|
||||
export(Tag)
|
||||
export(UpdatePetRequest)
|
||||
export(User)
|
||||
export(Whale)
|
||||
export(Zebra)
|
||||
|
||||
# APIs
|
||||
export(FakeApi)
|
||||
|
220
samples/client/petstore/R-httr2-wrapper/R/mammal.R
Normal file
220
samples/client/petstore/R-httr2-wrapper/R/mammal.R
Normal file
@ -0,0 +1,220 @@
|
||||
#' @docType class
|
||||
#' @title Mammal
|
||||
#'
|
||||
#' @description Mammal Class
|
||||
#'
|
||||
#' @format An \code{R6Class} generator object
|
||||
#'
|
||||
#' @importFrom R6 R6Class
|
||||
#' @importFrom jsonlite fromJSON toJSON
|
||||
#' @export
|
||||
Mammal <- R6::R6Class(
|
||||
"Mammal",
|
||||
public = list(
|
||||
#' @field actual_instance the object stored in this instance.
|
||||
actual_instance = NULL,
|
||||
#' @field actual_type the type of the object stored in this instance.
|
||||
actual_type = NULL,
|
||||
#' @field one_of a list of types defined in the oneOf schema.
|
||||
one_of = list("Whale", "Zebra"),
|
||||
#' Initialize a new Mammal.
|
||||
#'
|
||||
#' @description
|
||||
#' Initialize a new Mammal.
|
||||
#'
|
||||
#' @param instance an instance of the object defined in the oneOf schemas: "Whale", "Zebra"
|
||||
#' @export
|
||||
initialize = function(instance = NULL) {
|
||||
if (is.null(instance)) {
|
||||
# do nothing
|
||||
} else if (get(class(instance)[[1]], pos = -1)$classname == "Whale") {
|
||||
self$actual_instance <- instance
|
||||
self$actual_type <- "Whale"
|
||||
} else if (get(class(instance)[[1]], pos = -1)$classname == "Zebra") {
|
||||
self$actual_instance <- instance
|
||||
self$actual_type <- "Zebra"
|
||||
} else {
|
||||
stop(paste("Failed to initialize Mammal with oneOf schemas Whale, Zebra. Provided class name: ",
|
||||
get(class(instance)[[1]], pos = -1)$classname))
|
||||
}
|
||||
},
|
||||
#' Deserialize JSON string into an instance of Mammal.
|
||||
#'
|
||||
#' @description
|
||||
#' Deserialize JSON string into an instance of Mammal.
|
||||
#' An alias to the method `fromJSON` .
|
||||
#'
|
||||
#' @param input The input JSON.
|
||||
#' @return An instance of Mammal.
|
||||
#' @export
|
||||
fromJSONString = function(input) {
|
||||
self$fromJSON(input)
|
||||
},
|
||||
#' Deserialize JSON string into an instance of Mammal.
|
||||
#'
|
||||
#' @description
|
||||
#' Deserialize JSON string into an instance of Mammal.
|
||||
#'
|
||||
#' @param input The input JSON.
|
||||
#' @return An instance of Mammal.
|
||||
#' @export
|
||||
fromJSON = function(input) {
|
||||
matched <- 0 # match counter
|
||||
matched_schemas <- list() #names of matched schemas
|
||||
error_messages <- list()
|
||||
instance <- NULL
|
||||
|
||||
oneof_lookup_result <- tryCatch({
|
||||
discriminatorValue <- (jsonlite::fromJSON(input, simplifyVector = FALSE))$`className`
|
||||
switch(discriminatorValue,
|
||||
whale={
|
||||
Whale$public_methods$validateJSON(input)
|
||||
Whale_instance <- Whale$new()
|
||||
self$actual_instance <- Whale_instance$fromJSON(input)
|
||||
self$actual_type <- "Whale"
|
||||
return(self)
|
||||
},
|
||||
zebra={
|
||||
Zebra$public_methods$validateJSON(input)
|
||||
Zebra_instance <- Zebra$new()
|
||||
self$actual_instance <- Zebra_instance$fromJSON(input)
|
||||
self$actual_type <- "Zebra"
|
||||
return(self)
|
||||
})},
|
||||
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))
|
||||
}
|
||||
|
||||
Whale_result <- tryCatch({
|
||||
Whale$public_methods$validateJSON(input)
|
||||
Whale_instance <- Whale$new()
|
||||
instance <- Whale_instance$fromJSON(input)
|
||||
instance_type <- "Whale"
|
||||
matched_schemas <- append(matched_schemas, "Whale")
|
||||
matched <- matched + 1
|
||||
},
|
||||
error = function(err) err
|
||||
)
|
||||
|
||||
if (!is.null(Whale_result["error"])) {
|
||||
error_messages <- append(error_messages, Whale_result["message"])
|
||||
}
|
||||
|
||||
Zebra_result <- tryCatch({
|
||||
Zebra$public_methods$validateJSON(input)
|
||||
Zebra_instance <- Zebra$new()
|
||||
instance <- Zebra_instance$fromJSON(input)
|
||||
instance_type <- "Zebra"
|
||||
matched_schemas <- append(matched_schemas, "Zebra")
|
||||
matched <- matched + 1
|
||||
},
|
||||
error = function(err) err
|
||||
)
|
||||
|
||||
if (!is.null(Zebra_result["error"])) {
|
||||
error_messages <- append(error_messages, Zebra_result["message"])
|
||||
}
|
||||
|
||||
if (matched == 1) {
|
||||
# successfully match exactly 1 schema specified in oneOf
|
||||
self$actual_instance <- instance
|
||||
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.")
|
||||
} else {
|
||||
# no match
|
||||
stop(paste("No match found when deserializing the payload into Mammal with oneOf schemas Whale, Zebra. Details: ",
|
||||
paste(error_messages, collapse = ", ")))
|
||||
}
|
||||
|
||||
self
|
||||
},
|
||||
#' Serialize Mammal to JSON string.
|
||||
#'
|
||||
#' @description
|
||||
#' Serialize Mammal to JSON string.
|
||||
#'
|
||||
#' @return JSON string representation of the Mammal.
|
||||
#' @export
|
||||
toJSONString = function() {
|
||||
if (!is.null(self$actual_instance)) {
|
||||
as.character(jsonlite::minify(self$actual_instance$toJSONString()))
|
||||
} else {
|
||||
NULL
|
||||
}
|
||||
},
|
||||
#' Serialize Mammal to JSON.
|
||||
#'
|
||||
#' @description
|
||||
#' Serialize Mammal to JSON.
|
||||
#'
|
||||
#' @return JSON representation of the Mammal.
|
||||
#' @export
|
||||
toJSON = function() {
|
||||
if (!is.null(self$actual_instance)) {
|
||||
self$actual_instance$toJSON()
|
||||
} else {
|
||||
NULL
|
||||
}
|
||||
},
|
||||
#' Validate the input JSON with respect to Mammal.
|
||||
#'
|
||||
#' @description
|
||||
#' Validate the input JSON with respect to Mammal and
|
||||
#' throw exception if invalid.
|
||||
#'
|
||||
#' @param input The input JSON.
|
||||
#' @export
|
||||
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
|
||||
},
|
||||
#' Returns the string representation of the instance.
|
||||
#'
|
||||
#' @description
|
||||
#' Returns the string representation of the instance.
|
||||
#'
|
||||
#' @return The string representation of the instance.
|
||||
#' @export
|
||||
toString = function() {
|
||||
jsoncontent <- c(
|
||||
sprintf('"actual_instance": %s', if (is.null(self$actual_instance)) NULL else self$actual_instance$toJSONString()),
|
||||
sprintf('"actual_type": "%s"', self$actual_type),
|
||||
sprintf('"one_of": "%s"', paste(unlist(self$one_of), collapse = ", "))
|
||||
)
|
||||
jsoncontent <- paste(jsoncontent, collapse = ",")
|
||||
as.character(jsonlite::prettify(paste("{", jsoncontent, "}", sep = "")))
|
||||
}
|
||||
),
|
||||
# Lock the class to prevent modifications to the method or field
|
||||
lock_class = TRUE
|
||||
)
|
||||
|
||||
# Unlock the class to allow modifications of the method or field
|
||||
Mammal$unlock()
|
||||
|
||||
#' Print the object
|
||||
#'
|
||||
#' @description
|
||||
#' Print the object
|
||||
#'
|
||||
#' @export
|
||||
Mammal$set("public", "print", function(...) {
|
||||
print(jsonlite::prettify(self$toJSONString()))
|
||||
invisible(self)
|
||||
})
|
||||
|
||||
# Lock the class to prevent modifications to the method or field
|
||||
Mammal$lock()
|
||||
|
@ -64,6 +64,29 @@ Pig <- R6::R6Class(
|
||||
error_messages <- list()
|
||||
instance <- NULL
|
||||
|
||||
oneof_lookup_result <- tryCatch({
|
||||
discriminatorValue <- (jsonlite::fromJSON(input, simplifyVector = FALSE))$`className`
|
||||
switch(discriminatorValue,
|
||||
BasquePig={
|
||||
BasquePig$public_methods$validateJSON(input)
|
||||
BasquePig_instance <- BasquePig$new()
|
||||
self$actual_instance <- BasquePig_instance$fromJSON(input)
|
||||
self$actual_type <- "BasquePig"
|
||||
return(self)
|
||||
},
|
||||
DanishPig={
|
||||
DanishPig$public_methods$validateJSON(input)
|
||||
DanishPig_instance <- DanishPig$new()
|
||||
self$actual_instance <- DanishPig_instance$fromJSON(input)
|
||||
self$actual_type <- "DanishPig"
|
||||
return(self)
|
||||
})},
|
||||
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))
|
||||
}
|
||||
|
||||
BasquePig_result <- tryCatch({
|
||||
BasquePig$public_methods$validateJSON(input)
|
||||
BasquePig_instance <- BasquePig$new()
|
||||
|
223
samples/client/petstore/R-httr2-wrapper/R/whale.R
Normal file
223
samples/client/petstore/R-httr2-wrapper/R/whale.R
Normal file
@ -0,0 +1,223 @@
|
||||
#' Create a new Whale
|
||||
#'
|
||||
#' @description
|
||||
#' Whale Class
|
||||
#'
|
||||
#' @docType class
|
||||
#' @title Whale
|
||||
#' @description Whale Class
|
||||
#' @format An \code{R6Class} generator object
|
||||
#' @field hasBaleen character [optional]
|
||||
#' @field hasTeeth character [optional]
|
||||
#' @field className character
|
||||
#' @importFrom R6 R6Class
|
||||
#' @importFrom jsonlite fromJSON toJSON
|
||||
#' @export
|
||||
Whale <- R6::R6Class(
|
||||
"Whale",
|
||||
public = list(
|
||||
`hasBaleen` = NULL,
|
||||
`hasTeeth` = NULL,
|
||||
`className` = NULL,
|
||||
#' Initialize a new Whale class.
|
||||
#'
|
||||
#' @description
|
||||
#' Initialize a new Whale class.
|
||||
#'
|
||||
#' @param className className
|
||||
#' @param hasBaleen hasBaleen
|
||||
#' @param hasTeeth hasTeeth
|
||||
#' @param ... Other optional arguments.
|
||||
#' @export
|
||||
initialize = function(
|
||||
`className`, `hasBaleen` = NULL, `hasTeeth` = NULL, ...
|
||||
) {
|
||||
if (!missing(`className`)) {
|
||||
stopifnot(is.character(`className`), length(`className`) == 1)
|
||||
self$`className` <- `className`
|
||||
}
|
||||
if (!is.null(`hasBaleen`)) {
|
||||
stopifnot(is.logical(`hasBaleen`), length(`hasBaleen`) == 1)
|
||||
self$`hasBaleen` <- `hasBaleen`
|
||||
}
|
||||
if (!is.null(`hasTeeth`)) {
|
||||
stopifnot(is.logical(`hasTeeth`), length(`hasTeeth`) == 1)
|
||||
self$`hasTeeth` <- `hasTeeth`
|
||||
}
|
||||
},
|
||||
#' To JSON string
|
||||
#'
|
||||
#' @description
|
||||
#' To JSON String
|
||||
#'
|
||||
#' @return Whale in JSON format
|
||||
#' @export
|
||||
toJSON = function() {
|
||||
WhaleObject <- list()
|
||||
if (!is.null(self$`hasBaleen`)) {
|
||||
WhaleObject[["hasBaleen"]] <-
|
||||
self$`hasBaleen`
|
||||
}
|
||||
if (!is.null(self$`hasTeeth`)) {
|
||||
WhaleObject[["hasTeeth"]] <-
|
||||
self$`hasTeeth`
|
||||
}
|
||||
if (!is.null(self$`className`)) {
|
||||
WhaleObject[["className"]] <-
|
||||
self$`className`
|
||||
}
|
||||
|
||||
WhaleObject
|
||||
},
|
||||
#' Deserialize JSON string into an instance of Whale
|
||||
#'
|
||||
#' @description
|
||||
#' Deserialize JSON string into an instance of Whale
|
||||
#'
|
||||
#' @param input_json the JSON input
|
||||
#' @return the instance of Whale
|
||||
#' @export
|
||||
fromJSON = function(input_json) {
|
||||
this_object <- jsonlite::fromJSON(input_json)
|
||||
if (!is.null(this_object$`hasBaleen`)) {
|
||||
self$`hasBaleen` <- this_object$`hasBaleen`
|
||||
}
|
||||
if (!is.null(this_object$`hasTeeth`)) {
|
||||
self$`hasTeeth` <- this_object$`hasTeeth`
|
||||
}
|
||||
if (!is.null(this_object$`className`)) {
|
||||
self$`className` <- this_object$`className`
|
||||
}
|
||||
self
|
||||
},
|
||||
#' To JSON string
|
||||
#'
|
||||
#' @description
|
||||
#' To JSON String
|
||||
#'
|
||||
#' @return Whale in JSON format
|
||||
#' @export
|
||||
toJSONString = function() {
|
||||
jsoncontent <- c(
|
||||
if (!is.null(self$`hasBaleen`)) {
|
||||
sprintf(
|
||||
'"hasBaleen":
|
||||
%s
|
||||
',
|
||||
tolower(self$`hasBaleen`)
|
||||
)
|
||||
},
|
||||
if (!is.null(self$`hasTeeth`)) {
|
||||
sprintf(
|
||||
'"hasTeeth":
|
||||
%s
|
||||
',
|
||||
tolower(self$`hasTeeth`)
|
||||
)
|
||||
},
|
||||
if (!is.null(self$`className`)) {
|
||||
sprintf(
|
||||
'"className":
|
||||
"%s"
|
||||
',
|
||||
self$`className`
|
||||
)
|
||||
}
|
||||
)
|
||||
jsoncontent <- paste(jsoncontent, collapse = ",")
|
||||
as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = "")))
|
||||
},
|
||||
#' Deserialize JSON string into an instance of Whale
|
||||
#'
|
||||
#' @description
|
||||
#' Deserialize JSON string into an instance of Whale
|
||||
#'
|
||||
#' @param input_json the JSON input
|
||||
#' @return the instance of Whale
|
||||
#' @export
|
||||
fromJSONString = function(input_json) {
|
||||
this_object <- jsonlite::fromJSON(input_json)
|
||||
self$`hasBaleen` <- this_object$`hasBaleen`
|
||||
self$`hasTeeth` <- this_object$`hasTeeth`
|
||||
self$`className` <- this_object$`className`
|
||||
self
|
||||
},
|
||||
#' Validate JSON input with respect to Whale
|
||||
#'
|
||||
#' @description
|
||||
#' Validate JSON input with respect to Whale and throw an exception if invalid
|
||||
#'
|
||||
#' @param input the JSON input
|
||||
#' @export
|
||||
validateJSON = function(input) {
|
||||
input_json <- jsonlite::fromJSON(input)
|
||||
# check the required field `className`
|
||||
if (!is.null(input_json$`className`)) {
|
||||
stopifnot(is.character(input_json$`className`), length(input_json$`className`) == 1)
|
||||
} else {
|
||||
stop(paste("The JSON input `", input, "` is invalid for Whale: the required field `className` is missing."))
|
||||
}
|
||||
},
|
||||
#' To string (JSON format)
|
||||
#'
|
||||
#' @description
|
||||
#' To string (JSON format)
|
||||
#'
|
||||
#' @return String representation of Whale
|
||||
#' @export
|
||||
toString = function() {
|
||||
self$toJSONString()
|
||||
},
|
||||
#' Return true if the values in all fields are valid.
|
||||
#'
|
||||
#' @description
|
||||
#' Return true if the values in all fields are valid.
|
||||
#'
|
||||
#' @return true if the values in all fields are valid.
|
||||
#' @export
|
||||
isValid = function() {
|
||||
# check if the required `className` is null
|
||||
if (is.null(self$`className`)) {
|
||||
return(FALSE)
|
||||
}
|
||||
|
||||
TRUE
|
||||
},
|
||||
#' Return a list of invalid fields (if any).
|
||||
#'
|
||||
#' @description
|
||||
#' Return a list of invalid fields (if any).
|
||||
#'
|
||||
#' @return A list of invalid fields (if any).
|
||||
#' @export
|
||||
getInvalidFields = function() {
|
||||
invalid_fields <- list()
|
||||
# check if the required `className` is null
|
||||
if (is.null(self$`className`)) {
|
||||
invalid_fields["className"] <- "Non-nullable required field `className` cannot be null."
|
||||
}
|
||||
|
||||
invalid_fields
|
||||
}
|
||||
),
|
||||
# Lock the class to prevent modifications to the method or field
|
||||
lock_class = TRUE
|
||||
)
|
||||
|
||||
# Unlock the class to allow modifications of the method or field
|
||||
Whale$unlock()
|
||||
|
||||
#' Print the object
|
||||
#'
|
||||
#' @description
|
||||
#' Print the object
|
||||
#'
|
||||
#' @export
|
||||
Whale$set("public", "print", function(...) {
|
||||
print(jsonlite::prettify(self$toJSONString()))
|
||||
invisible(self)
|
||||
})
|
||||
|
||||
# Lock the class to prevent modifications to the method or field
|
||||
Whale$lock()
|
||||
|
200
samples/client/petstore/R-httr2-wrapper/R/zebra.R
Normal file
200
samples/client/petstore/R-httr2-wrapper/R/zebra.R
Normal file
@ -0,0 +1,200 @@
|
||||
#' Create a new Zebra
|
||||
#'
|
||||
#' @description
|
||||
#' Zebra Class
|
||||
#'
|
||||
#' @docType class
|
||||
#' @title Zebra
|
||||
#' @description Zebra Class
|
||||
#' @format An \code{R6Class} generator object
|
||||
#' @field type character [optional]
|
||||
#' @field className character
|
||||
#' @importFrom R6 R6Class
|
||||
#' @importFrom jsonlite fromJSON toJSON
|
||||
#' @export
|
||||
Zebra <- R6::R6Class(
|
||||
"Zebra",
|
||||
public = list(
|
||||
`type` = NULL,
|
||||
`className` = NULL,
|
||||
#' Initialize a new Zebra class.
|
||||
#'
|
||||
#' @description
|
||||
#' Initialize a new Zebra class.
|
||||
#'
|
||||
#' @param className className
|
||||
#' @param type type
|
||||
#' @param ... Other optional arguments.
|
||||
#' @export
|
||||
initialize = function(
|
||||
`className`, `type` = NULL, ...
|
||||
) {
|
||||
if (!missing(`className`)) {
|
||||
stopifnot(is.character(`className`), length(`className`) == 1)
|
||||
self$`className` <- `className`
|
||||
}
|
||||
if (!is.null(`type`)) {
|
||||
stopifnot(is.character(`type`), length(`type`) == 1)
|
||||
self$`type` <- `type`
|
||||
}
|
||||
},
|
||||
#' To JSON string
|
||||
#'
|
||||
#' @description
|
||||
#' To JSON String
|
||||
#'
|
||||
#' @return Zebra in JSON format
|
||||
#' @export
|
||||
toJSON = function() {
|
||||
ZebraObject <- list()
|
||||
if (!is.null(self$`type`)) {
|
||||
ZebraObject[["type"]] <-
|
||||
self$`type`
|
||||
}
|
||||
if (!is.null(self$`className`)) {
|
||||
ZebraObject[["className"]] <-
|
||||
self$`className`
|
||||
}
|
||||
|
||||
ZebraObject
|
||||
},
|
||||
#' Deserialize JSON string into an instance of Zebra
|
||||
#'
|
||||
#' @description
|
||||
#' Deserialize JSON string into an instance of Zebra
|
||||
#'
|
||||
#' @param input_json the JSON input
|
||||
#' @return the instance of Zebra
|
||||
#' @export
|
||||
fromJSON = function(input_json) {
|
||||
this_object <- jsonlite::fromJSON(input_json)
|
||||
if (!is.null(this_object$`type`)) {
|
||||
self$`type` <- this_object$`type`
|
||||
}
|
||||
if (!is.null(this_object$`className`)) {
|
||||
self$`className` <- this_object$`className`
|
||||
}
|
||||
self
|
||||
},
|
||||
#' To JSON string
|
||||
#'
|
||||
#' @description
|
||||
#' To JSON String
|
||||
#'
|
||||
#' @return Zebra in JSON format
|
||||
#' @export
|
||||
toJSONString = function() {
|
||||
jsoncontent <- c(
|
||||
if (!is.null(self$`type`)) {
|
||||
sprintf(
|
||||
'"type":
|
||||
"%s"
|
||||
',
|
||||
self$`type`
|
||||
)
|
||||
},
|
||||
if (!is.null(self$`className`)) {
|
||||
sprintf(
|
||||
'"className":
|
||||
"%s"
|
||||
',
|
||||
self$`className`
|
||||
)
|
||||
}
|
||||
)
|
||||
jsoncontent <- paste(jsoncontent, collapse = ",")
|
||||
as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = "")))
|
||||
},
|
||||
#' Deserialize JSON string into an instance of Zebra
|
||||
#'
|
||||
#' @description
|
||||
#' Deserialize JSON string into an instance of Zebra
|
||||
#'
|
||||
#' @param input_json the JSON input
|
||||
#' @return the instance of Zebra
|
||||
#' @export
|
||||
fromJSONString = function(input_json) {
|
||||
this_object <- jsonlite::fromJSON(input_json)
|
||||
self$`type` <- this_object$`type`
|
||||
self$`className` <- this_object$`className`
|
||||
self
|
||||
},
|
||||
#' Validate JSON input with respect to Zebra
|
||||
#'
|
||||
#' @description
|
||||
#' Validate JSON input with respect to Zebra and throw an exception if invalid
|
||||
#'
|
||||
#' @param input the JSON input
|
||||
#' @export
|
||||
validateJSON = function(input) {
|
||||
input_json <- jsonlite::fromJSON(input)
|
||||
# check the required field `className`
|
||||
if (!is.null(input_json$`className`)) {
|
||||
stopifnot(is.character(input_json$`className`), length(input_json$`className`) == 1)
|
||||
} else {
|
||||
stop(paste("The JSON input `", input, "` is invalid for Zebra: the required field `className` is missing."))
|
||||
}
|
||||
},
|
||||
#' To string (JSON format)
|
||||
#'
|
||||
#' @description
|
||||
#' To string (JSON format)
|
||||
#'
|
||||
#' @return String representation of Zebra
|
||||
#' @export
|
||||
toString = function() {
|
||||
self$toJSONString()
|
||||
},
|
||||
#' Return true if the values in all fields are valid.
|
||||
#'
|
||||
#' @description
|
||||
#' Return true if the values in all fields are valid.
|
||||
#'
|
||||
#' @return true if the values in all fields are valid.
|
||||
#' @export
|
||||
isValid = function() {
|
||||
# check if the required `className` is null
|
||||
if (is.null(self$`className`)) {
|
||||
return(FALSE)
|
||||
}
|
||||
|
||||
TRUE
|
||||
},
|
||||
#' Return a list of invalid fields (if any).
|
||||
#'
|
||||
#' @description
|
||||
#' Return a list of invalid fields (if any).
|
||||
#'
|
||||
#' @return A list of invalid fields (if any).
|
||||
#' @export
|
||||
getInvalidFields = function() {
|
||||
invalid_fields <- list()
|
||||
# check if the required `className` is null
|
||||
if (is.null(self$`className`)) {
|
||||
invalid_fields["className"] <- "Non-nullable required field `className` cannot be null."
|
||||
}
|
||||
|
||||
invalid_fields
|
||||
}
|
||||
),
|
||||
# Lock the class to prevent modifications to the method or field
|
||||
lock_class = TRUE
|
||||
)
|
||||
|
||||
# Unlock the class to allow modifications of the method or field
|
||||
Zebra$unlock()
|
||||
|
||||
#' Print the object
|
||||
#'
|
||||
#' @description
|
||||
#' Print the object
|
||||
#'
|
||||
#' @export
|
||||
Zebra$set("public", "print", function(...) {
|
||||
print(jsonlite::prettify(self$toJSONString()))
|
||||
invisible(self)
|
||||
})
|
||||
|
||||
# Lock the class to prevent modifications to the method or field
|
||||
Zebra$lock()
|
||||
|
@ -100,6 +100,7 @@ Class | Method | HTTP request | Description
|
||||
- [DanishPig](docs/DanishPig.md)
|
||||
- [Dog](docs/Dog.md)
|
||||
- [DogAllOf](docs/DogAllOf.md)
|
||||
- [Mammal](docs/Mammal.md)
|
||||
- [ModelApiResponse](docs/ModelApiResponse.md)
|
||||
- [NestedOneOf](docs/NestedOneOf.md)
|
||||
- [OneOfPrimitiveTypeTest](docs/OneOfPrimitiveTypeTest.md)
|
||||
@ -110,6 +111,8 @@ Class | Method | HTTP request | Description
|
||||
- [Tag](docs/Tag.md)
|
||||
- [UpdatePetRequest](docs/UpdatePetRequest.md)
|
||||
- [User](docs/User.md)
|
||||
- [Whale](docs/Whale.md)
|
||||
- [Zebra](docs/Zebra.md)
|
||||
|
||||
|
||||
## Documentation for Authorization
|
||||
|
12
samples/client/petstore/R-httr2-wrapper/docs/Mammal.md
Normal file
12
samples/client/petstore/R-httr2-wrapper/docs/Mammal.md
Normal file
@ -0,0 +1,12 @@
|
||||
# petstore::Mammal
|
||||
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**hasBaleen** | **character** | | [optional]
|
||||
**hasTeeth** | **character** | | [optional]
|
||||
**className** | **character** | |
|
||||
**type** | **character** | | [optional]
|
||||
|
||||
|
11
samples/client/petstore/R-httr2-wrapper/docs/Whale.md
Normal file
11
samples/client/petstore/R-httr2-wrapper/docs/Whale.md
Normal file
@ -0,0 +1,11 @@
|
||||
# petstore::Whale
|
||||
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**hasBaleen** | **character** | | [optional]
|
||||
**hasTeeth** | **character** | | [optional]
|
||||
**className** | **character** | |
|
||||
|
||||
|
10
samples/client/petstore/R-httr2-wrapper/docs/Zebra.md
Normal file
10
samples/client/petstore/R-httr2-wrapper/docs/Zebra.md
Normal file
@ -0,0 +1,10 @@
|
||||
# petstore::Zebra
|
||||
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**type** | **character** | | [optional]
|
||||
**className** | **character** | |
|
||||
|
||||
|
@ -3,6 +3,12 @@ install.packages("petstore_1.0.0.tar.gz",repos=NULL, type="source")
|
||||
library(petstore)
|
||||
library(jsonlite)
|
||||
|
||||
whale_json <- '{"className": "whale", "hasBaleen": true, "hasTeeth": true}'
|
||||
zebra_json <- '{"className": "zebra", "type": "plains"}'
|
||||
|
||||
mammal <- Mammal$new()
|
||||
mammal$fromJSON(whale_json)
|
||||
|
||||
api_client <- ApiClient$new()
|
||||
api_client$username <- "username999"
|
||||
api_client$password <- "password888"
|
||||
|
@ -0,0 +1,34 @@
|
||||
# Automatically generated by openapi-generator (https://openapi-generator.tech)
|
||||
# Please update as you see appropriate
|
||||
|
||||
context("Test Mammal")
|
||||
|
||||
model_instance <- Mammal$new()
|
||||
|
||||
test_that("hasBaleen", {
|
||||
# tests for the property `hasBaleen` (character)
|
||||
|
||||
# uncomment below to test the property
|
||||
#expect_equal(model.instance$`hasBaleen`, "EXPECTED_RESULT")
|
||||
})
|
||||
|
||||
test_that("hasTeeth", {
|
||||
# tests for the property `hasTeeth` (character)
|
||||
|
||||
# uncomment below to test the property
|
||||
#expect_equal(model.instance$`hasTeeth`, "EXPECTED_RESULT")
|
||||
})
|
||||
|
||||
test_that("className", {
|
||||
# tests for the property `className` (character)
|
||||
|
||||
# uncomment below to test the property
|
||||
#expect_equal(model.instance$`className`, "EXPECTED_RESULT")
|
||||
})
|
||||
|
||||
test_that("type", {
|
||||
# tests for the property `type` (character)
|
||||
|
||||
# uncomment below to test the property
|
||||
#expect_equal(model.instance$`type`, "EXPECTED_RESULT")
|
||||
})
|
@ -294,6 +294,22 @@ test_that ("Tests validations", {
|
||||
|
||||
})
|
||||
|
||||
test_that("Tests oneOf discriminator mapping", {
|
||||
whale_json <- '{"className": "whale", "hasBaleen": true, "hasTeeth": true}'
|
||||
zebra_json <- '{"className": "zebra", "type": "plains"}'
|
||||
|
||||
mammal <- Mammal$new()
|
||||
mammal$fromJSON(whale_json)
|
||||
expect_equal(mammal$actual_type, "Whale")
|
||||
expect_equal(mammal$actual_instance$hasBaleen, TRUE)
|
||||
expect_equal(mammal$actual_instance$hasTeeth, TRUE)
|
||||
|
||||
mammal$fromJSON(zebra_json)
|
||||
expect_equal(mammal$actual_type, "Zebra")
|
||||
expect_equal(mammal$actual_instance$type, "plains")
|
||||
|
||||
})
|
||||
|
||||
test_that("Tests oneOf", {
|
||||
basque_pig_json <-
|
||||
'{"className": "BasquePig", "color": "red"}'
|
||||
@ -333,8 +349,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 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\\.')
|
||||
|
||||
# class name test
|
||||
expect_equal(get(class(basque_pig$actual_instance)[[1]], pos = -1)$classname, "BasquePig")
|
||||
|
@ -0,0 +1,27 @@
|
||||
# Automatically generated by openapi-generator (https://openapi-generator.tech)
|
||||
# Please update as you see appropriate
|
||||
|
||||
context("Test Whale")
|
||||
|
||||
model_instance <- Whale$new()
|
||||
|
||||
test_that("hasBaleen", {
|
||||
# tests for the property `hasBaleen` (character)
|
||||
|
||||
# uncomment below to test the property
|
||||
#expect_equal(model.instance$`hasBaleen`, "EXPECTED_RESULT")
|
||||
})
|
||||
|
||||
test_that("hasTeeth", {
|
||||
# tests for the property `hasTeeth` (character)
|
||||
|
||||
# uncomment below to test the property
|
||||
#expect_equal(model.instance$`hasTeeth`, "EXPECTED_RESULT")
|
||||
})
|
||||
|
||||
test_that("className", {
|
||||
# tests for the property `className` (character)
|
||||
|
||||
# uncomment below to test the property
|
||||
#expect_equal(model.instance$`className`, "EXPECTED_RESULT")
|
||||
})
|
@ -0,0 +1,20 @@
|
||||
# Automatically generated by openapi-generator (https://openapi-generator.tech)
|
||||
# Please update as you see appropriate
|
||||
|
||||
context("Test Zebra")
|
||||
|
||||
model_instance <- Zebra$new()
|
||||
|
||||
test_that("type", {
|
||||
# tests for the property `type` (character)
|
||||
|
||||
# uncomment below to test the property
|
||||
#expect_equal(model.instance$`type`, "EXPECTED_RESULT")
|
||||
})
|
||||
|
||||
test_that("className", {
|
||||
# tests for the property `className` (character)
|
||||
|
||||
# uncomment below to test the property
|
||||
#expect_equal(model.instance$`className`, "EXPECTED_RESULT")
|
||||
})
|
@ -20,6 +20,7 @@ R/danish_pig.R
|
||||
R/dog.R
|
||||
R/dog_all_of.R
|
||||
R/fake_api.R
|
||||
R/mammal.R
|
||||
R/model_api_response.R
|
||||
R/nested_one_of.R
|
||||
R/one_of_primitive_type_test.R
|
||||
@ -33,6 +34,8 @@ R/tag.R
|
||||
R/update_pet_request.R
|
||||
R/user.R
|
||||
R/user_api.R
|
||||
R/whale.R
|
||||
R/zebra.R
|
||||
README.md
|
||||
docs/AllofTagApiResponse.md
|
||||
docs/Animal.md
|
||||
@ -46,6 +49,7 @@ docs/DanishPig.md
|
||||
docs/Dog.md
|
||||
docs/DogAllOf.md
|
||||
docs/FakeApi.md
|
||||
docs/Mammal.md
|
||||
docs/ModelApiResponse.md
|
||||
docs/NestedOneOf.md
|
||||
docs/OneOfPrimitiveTypeTest.md
|
||||
@ -59,5 +63,7 @@ docs/Tag.md
|
||||
docs/UpdatePetRequest.md
|
||||
docs/User.md
|
||||
docs/UserApi.md
|
||||
docs/Whale.md
|
||||
docs/Zebra.md
|
||||
git_push.sh
|
||||
tests/testthat.R
|
||||
|
@ -25,6 +25,7 @@ export(Category)
|
||||
export(DanishPig)
|
||||
export(Dog)
|
||||
export(DogAllOf)
|
||||
export(Mammal)
|
||||
export(ModelApiResponse)
|
||||
export(NestedOneOf)
|
||||
export(OneOfPrimitiveTypeTest)
|
||||
@ -35,6 +36,8 @@ export(Special)
|
||||
export(Tag)
|
||||
export(UpdatePetRequest)
|
||||
export(User)
|
||||
export(Whale)
|
||||
export(Zebra)
|
||||
|
||||
# APIs
|
||||
export(FakeApi)
|
||||
|
197
samples/client/petstore/R-httr2/R/mammal.R
Normal file
197
samples/client/petstore/R-httr2/R/mammal.R
Normal file
@ -0,0 +1,197 @@
|
||||
#' @docType class
|
||||
#' @title Mammal
|
||||
#'
|
||||
#' @description Mammal Class
|
||||
#'
|
||||
#' @format An \code{R6Class} generator object
|
||||
#'
|
||||
#' @importFrom R6 R6Class
|
||||
#' @importFrom jsonlite fromJSON toJSON
|
||||
#' @export
|
||||
Mammal <- R6::R6Class(
|
||||
"Mammal",
|
||||
public = list(
|
||||
#' @field actual_instance the object stored in this instance.
|
||||
actual_instance = NULL,
|
||||
#' @field actual_type the type of the object stored in this instance.
|
||||
actual_type = NULL,
|
||||
#' @field one_of a list of types defined in the oneOf schema.
|
||||
one_of = list("Whale", "Zebra"),
|
||||
#' Initialize a new Mammal.
|
||||
#'
|
||||
#' @description
|
||||
#' Initialize a new Mammal.
|
||||
#'
|
||||
#' @param instance an instance of the object defined in the oneOf schemas: "Whale", "Zebra"
|
||||
#' @export
|
||||
initialize = function(instance = NULL) {
|
||||
if (is.null(instance)) {
|
||||
# do nothing
|
||||
} else if (get(class(instance)[[1]], pos = -1)$classname == "Whale") {
|
||||
self$actual_instance <- instance
|
||||
self$actual_type <- "Whale"
|
||||
} else if (get(class(instance)[[1]], pos = -1)$classname == "Zebra") {
|
||||
self$actual_instance <- instance
|
||||
self$actual_type <- "Zebra"
|
||||
} else {
|
||||
stop(paste("Failed to initialize Mammal with oneOf schemas Whale, Zebra. Provided class name: ",
|
||||
get(class(instance)[[1]], pos = -1)$classname))
|
||||
}
|
||||
},
|
||||
#' Deserialize JSON string into an instance of Mammal.
|
||||
#'
|
||||
#' @description
|
||||
#' Deserialize JSON string into an instance of Mammal.
|
||||
#' An alias to the method `fromJSON` .
|
||||
#'
|
||||
#' @param input The input JSON.
|
||||
#' @return An instance of Mammal.
|
||||
#' @export
|
||||
fromJSONString = function(input) {
|
||||
self$fromJSON(input)
|
||||
},
|
||||
#' Deserialize JSON string into an instance of Mammal.
|
||||
#'
|
||||
#' @description
|
||||
#' Deserialize JSON string into an instance of Mammal.
|
||||
#'
|
||||
#' @param input The input JSON.
|
||||
#' @return An instance of Mammal.
|
||||
#' @export
|
||||
fromJSON = function(input) {
|
||||
matched <- 0 # match counter
|
||||
matched_schemas <- list() #names of matched schemas
|
||||
error_messages <- list()
|
||||
instance <- NULL
|
||||
|
||||
Whale_result <- tryCatch({
|
||||
Whale$public_methods$validateJSON(input)
|
||||
Whale_instance <- Whale$new()
|
||||
instance <- Whale_instance$fromJSON(input)
|
||||
instance_type <- "Whale"
|
||||
matched_schemas <- append(matched_schemas, "Whale")
|
||||
matched <- matched + 1
|
||||
},
|
||||
error = function(err) err
|
||||
)
|
||||
|
||||
if (!is.null(Whale_result["error"])) {
|
||||
error_messages <- append(error_messages, Whale_result["message"])
|
||||
}
|
||||
|
||||
Zebra_result <- tryCatch({
|
||||
Zebra$public_methods$validateJSON(input)
|
||||
Zebra_instance <- Zebra$new()
|
||||
instance <- Zebra_instance$fromJSON(input)
|
||||
instance_type <- "Zebra"
|
||||
matched_schemas <- append(matched_schemas, "Zebra")
|
||||
matched <- matched + 1
|
||||
},
|
||||
error = function(err) err
|
||||
)
|
||||
|
||||
if (!is.null(Zebra_result["error"])) {
|
||||
error_messages <- append(error_messages, Zebra_result["message"])
|
||||
}
|
||||
|
||||
if (matched == 1) {
|
||||
# successfully match exactly 1 schema specified in oneOf
|
||||
self$actual_instance <- instance
|
||||
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.")
|
||||
} else {
|
||||
# no match
|
||||
stop(paste("No match found when deserializing the payload into Mammal with oneOf schemas Whale, Zebra. Details: ",
|
||||
paste(error_messages, collapse = ", ")))
|
||||
}
|
||||
|
||||
self
|
||||
},
|
||||
#' Serialize Mammal to JSON string.
|
||||
#'
|
||||
#' @description
|
||||
#' Serialize Mammal to JSON string.
|
||||
#'
|
||||
#' @return JSON string representation of the Mammal.
|
||||
#' @export
|
||||
toJSONString = function() {
|
||||
if (!is.null(self$actual_instance)) {
|
||||
as.character(jsonlite::minify(self$actual_instance$toJSONString()))
|
||||
} else {
|
||||
NULL
|
||||
}
|
||||
},
|
||||
#' Serialize Mammal to JSON.
|
||||
#'
|
||||
#' @description
|
||||
#' Serialize Mammal to JSON.
|
||||
#'
|
||||
#' @return JSON representation of the Mammal.
|
||||
#' @export
|
||||
toJSON = function() {
|
||||
if (!is.null(self$actual_instance)) {
|
||||
self$actual_instance$toJSON()
|
||||
} else {
|
||||
NULL
|
||||
}
|
||||
},
|
||||
#' Validate the input JSON with respect to Mammal.
|
||||
#'
|
||||
#' @description
|
||||
#' Validate the input JSON with respect to Mammal and
|
||||
#' throw exception if invalid.
|
||||
#'
|
||||
#' @param input The input JSON.
|
||||
#' @export
|
||||
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
|
||||
},
|
||||
#' Returns the string representation of the instance.
|
||||
#'
|
||||
#' @description
|
||||
#' Returns the string representation of the instance.
|
||||
#'
|
||||
#' @return The string representation of the instance.
|
||||
#' @export
|
||||
toString = function() {
|
||||
jsoncontent <- c(
|
||||
sprintf('"actual_instance": %s', if (is.null(self$actual_instance)) NULL else self$actual_instance$toJSONString()),
|
||||
sprintf('"actual_type": "%s"', self$actual_type),
|
||||
sprintf('"one_of": "%s"', paste(unlist(self$one_of), collapse = ", "))
|
||||
)
|
||||
jsoncontent <- paste(jsoncontent, collapse = ",")
|
||||
as.character(jsonlite::prettify(paste("{", jsoncontent, "}", sep = "")))
|
||||
}
|
||||
),
|
||||
# Lock the class to prevent modifications to the method or field
|
||||
lock_class = TRUE
|
||||
)
|
||||
|
||||
# Unlock the class to allow modifications of the method or field
|
||||
Mammal$unlock()
|
||||
|
||||
#' Print the object
|
||||
#'
|
||||
#' @description
|
||||
#' Print the object
|
||||
#'
|
||||
#' @export
|
||||
Mammal$set("public", "print", function(...) {
|
||||
print(jsonlite::prettify(self$toJSONString()))
|
||||
invisible(self)
|
||||
})
|
||||
|
||||
# Lock the class to prevent modifications to the method or field
|
||||
Mammal$lock()
|
||||
|
223
samples/client/petstore/R-httr2/R/whale.R
Normal file
223
samples/client/petstore/R-httr2/R/whale.R
Normal file
@ -0,0 +1,223 @@
|
||||
#' Create a new Whale
|
||||
#'
|
||||
#' @description
|
||||
#' Whale Class
|
||||
#'
|
||||
#' @docType class
|
||||
#' @title Whale
|
||||
#' @description Whale Class
|
||||
#' @format An \code{R6Class} generator object
|
||||
#' @field hasBaleen character [optional]
|
||||
#' @field hasTeeth character [optional]
|
||||
#' @field className character
|
||||
#' @importFrom R6 R6Class
|
||||
#' @importFrom jsonlite fromJSON toJSON
|
||||
#' @export
|
||||
Whale <- R6::R6Class(
|
||||
"Whale",
|
||||
public = list(
|
||||
`hasBaleen` = NULL,
|
||||
`hasTeeth` = NULL,
|
||||
`className` = NULL,
|
||||
#' Initialize a new Whale class.
|
||||
#'
|
||||
#' @description
|
||||
#' Initialize a new Whale class.
|
||||
#'
|
||||
#' @param className className
|
||||
#' @param hasBaleen hasBaleen
|
||||
#' @param hasTeeth hasTeeth
|
||||
#' @param ... Other optional arguments.
|
||||
#' @export
|
||||
initialize = function(
|
||||
`className`, `hasBaleen` = NULL, `hasTeeth` = NULL, ...
|
||||
) {
|
||||
if (!missing(`className`)) {
|
||||
stopifnot(is.character(`className`), length(`className`) == 1)
|
||||
self$`className` <- `className`
|
||||
}
|
||||
if (!is.null(`hasBaleen`)) {
|
||||
stopifnot(is.logical(`hasBaleen`), length(`hasBaleen`) == 1)
|
||||
self$`hasBaleen` <- `hasBaleen`
|
||||
}
|
||||
if (!is.null(`hasTeeth`)) {
|
||||
stopifnot(is.logical(`hasTeeth`), length(`hasTeeth`) == 1)
|
||||
self$`hasTeeth` <- `hasTeeth`
|
||||
}
|
||||
},
|
||||
#' To JSON string
|
||||
#'
|
||||
#' @description
|
||||
#' To JSON String
|
||||
#'
|
||||
#' @return Whale in JSON format
|
||||
#' @export
|
||||
toJSON = function() {
|
||||
WhaleObject <- list()
|
||||
if (!is.null(self$`hasBaleen`)) {
|
||||
WhaleObject[["hasBaleen"]] <-
|
||||
self$`hasBaleen`
|
||||
}
|
||||
if (!is.null(self$`hasTeeth`)) {
|
||||
WhaleObject[["hasTeeth"]] <-
|
||||
self$`hasTeeth`
|
||||
}
|
||||
if (!is.null(self$`className`)) {
|
||||
WhaleObject[["className"]] <-
|
||||
self$`className`
|
||||
}
|
||||
|
||||
WhaleObject
|
||||
},
|
||||
#' Deserialize JSON string into an instance of Whale
|
||||
#'
|
||||
#' @description
|
||||
#' Deserialize JSON string into an instance of Whale
|
||||
#'
|
||||
#' @param input_json the JSON input
|
||||
#' @return the instance of Whale
|
||||
#' @export
|
||||
fromJSON = function(input_json) {
|
||||
this_object <- jsonlite::fromJSON(input_json)
|
||||
if (!is.null(this_object$`hasBaleen`)) {
|
||||
self$`hasBaleen` <- this_object$`hasBaleen`
|
||||
}
|
||||
if (!is.null(this_object$`hasTeeth`)) {
|
||||
self$`hasTeeth` <- this_object$`hasTeeth`
|
||||
}
|
||||
if (!is.null(this_object$`className`)) {
|
||||
self$`className` <- this_object$`className`
|
||||
}
|
||||
self
|
||||
},
|
||||
#' To JSON string
|
||||
#'
|
||||
#' @description
|
||||
#' To JSON String
|
||||
#'
|
||||
#' @return Whale in JSON format
|
||||
#' @export
|
||||
toJSONString = function() {
|
||||
jsoncontent <- c(
|
||||
if (!is.null(self$`hasBaleen`)) {
|
||||
sprintf(
|
||||
'"hasBaleen":
|
||||
%s
|
||||
',
|
||||
tolower(self$`hasBaleen`)
|
||||
)
|
||||
},
|
||||
if (!is.null(self$`hasTeeth`)) {
|
||||
sprintf(
|
||||
'"hasTeeth":
|
||||
%s
|
||||
',
|
||||
tolower(self$`hasTeeth`)
|
||||
)
|
||||
},
|
||||
if (!is.null(self$`className`)) {
|
||||
sprintf(
|
||||
'"className":
|
||||
"%s"
|
||||
',
|
||||
self$`className`
|
||||
)
|
||||
}
|
||||
)
|
||||
jsoncontent <- paste(jsoncontent, collapse = ",")
|
||||
as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = "")))
|
||||
},
|
||||
#' Deserialize JSON string into an instance of Whale
|
||||
#'
|
||||
#' @description
|
||||
#' Deserialize JSON string into an instance of Whale
|
||||
#'
|
||||
#' @param input_json the JSON input
|
||||
#' @return the instance of Whale
|
||||
#' @export
|
||||
fromJSONString = function(input_json) {
|
||||
this_object <- jsonlite::fromJSON(input_json)
|
||||
self$`hasBaleen` <- this_object$`hasBaleen`
|
||||
self$`hasTeeth` <- this_object$`hasTeeth`
|
||||
self$`className` <- this_object$`className`
|
||||
self
|
||||
},
|
||||
#' Validate JSON input with respect to Whale
|
||||
#'
|
||||
#' @description
|
||||
#' Validate JSON input with respect to Whale and throw an exception if invalid
|
||||
#'
|
||||
#' @param input the JSON input
|
||||
#' @export
|
||||
validateJSON = function(input) {
|
||||
input_json <- jsonlite::fromJSON(input)
|
||||
# check the required field `className`
|
||||
if (!is.null(input_json$`className`)) {
|
||||
stopifnot(is.character(input_json$`className`), length(input_json$`className`) == 1)
|
||||
} else {
|
||||
stop(paste("The JSON input `", input, "` is invalid for Whale: the required field `className` is missing."))
|
||||
}
|
||||
},
|
||||
#' To string (JSON format)
|
||||
#'
|
||||
#' @description
|
||||
#' To string (JSON format)
|
||||
#'
|
||||
#' @return String representation of Whale
|
||||
#' @export
|
||||
toString = function() {
|
||||
self$toJSONString()
|
||||
},
|
||||
#' Return true if the values in all fields are valid.
|
||||
#'
|
||||
#' @description
|
||||
#' Return true if the values in all fields are valid.
|
||||
#'
|
||||
#' @return true if the values in all fields are valid.
|
||||
#' @export
|
||||
isValid = function() {
|
||||
# check if the required `className` is null
|
||||
if (is.null(self$`className`)) {
|
||||
return(FALSE)
|
||||
}
|
||||
|
||||
TRUE
|
||||
},
|
||||
#' Return a list of invalid fields (if any).
|
||||
#'
|
||||
#' @description
|
||||
#' Return a list of invalid fields (if any).
|
||||
#'
|
||||
#' @return A list of invalid fields (if any).
|
||||
#' @export
|
||||
getInvalidFields = function() {
|
||||
invalid_fields <- list()
|
||||
# check if the required `className` is null
|
||||
if (is.null(self$`className`)) {
|
||||
invalid_fields["className"] <- "Non-nullable required field `className` cannot be null."
|
||||
}
|
||||
|
||||
invalid_fields
|
||||
}
|
||||
),
|
||||
# Lock the class to prevent modifications to the method or field
|
||||
lock_class = TRUE
|
||||
)
|
||||
|
||||
# Unlock the class to allow modifications of the method or field
|
||||
Whale$unlock()
|
||||
|
||||
#' Print the object
|
||||
#'
|
||||
#' @description
|
||||
#' Print the object
|
||||
#'
|
||||
#' @export
|
||||
Whale$set("public", "print", function(...) {
|
||||
print(jsonlite::prettify(self$toJSONString()))
|
||||
invisible(self)
|
||||
})
|
||||
|
||||
# Lock the class to prevent modifications to the method or field
|
||||
Whale$lock()
|
||||
|
200
samples/client/petstore/R-httr2/R/zebra.R
Normal file
200
samples/client/petstore/R-httr2/R/zebra.R
Normal file
@ -0,0 +1,200 @@
|
||||
#' Create a new Zebra
|
||||
#'
|
||||
#' @description
|
||||
#' Zebra Class
|
||||
#'
|
||||
#' @docType class
|
||||
#' @title Zebra
|
||||
#' @description Zebra Class
|
||||
#' @format An \code{R6Class} generator object
|
||||
#' @field type character [optional]
|
||||
#' @field className character
|
||||
#' @importFrom R6 R6Class
|
||||
#' @importFrom jsonlite fromJSON toJSON
|
||||
#' @export
|
||||
Zebra <- R6::R6Class(
|
||||
"Zebra",
|
||||
public = list(
|
||||
`type` = NULL,
|
||||
`className` = NULL,
|
||||
#' Initialize a new Zebra class.
|
||||
#'
|
||||
#' @description
|
||||
#' Initialize a new Zebra class.
|
||||
#'
|
||||
#' @param className className
|
||||
#' @param type type
|
||||
#' @param ... Other optional arguments.
|
||||
#' @export
|
||||
initialize = function(
|
||||
`className`, `type` = NULL, ...
|
||||
) {
|
||||
if (!missing(`className`)) {
|
||||
stopifnot(is.character(`className`), length(`className`) == 1)
|
||||
self$`className` <- `className`
|
||||
}
|
||||
if (!is.null(`type`)) {
|
||||
stopifnot(is.character(`type`), length(`type`) == 1)
|
||||
self$`type` <- `type`
|
||||
}
|
||||
},
|
||||
#' To JSON string
|
||||
#'
|
||||
#' @description
|
||||
#' To JSON String
|
||||
#'
|
||||
#' @return Zebra in JSON format
|
||||
#' @export
|
||||
toJSON = function() {
|
||||
ZebraObject <- list()
|
||||
if (!is.null(self$`type`)) {
|
||||
ZebraObject[["type"]] <-
|
||||
self$`type`
|
||||
}
|
||||
if (!is.null(self$`className`)) {
|
||||
ZebraObject[["className"]] <-
|
||||
self$`className`
|
||||
}
|
||||
|
||||
ZebraObject
|
||||
},
|
||||
#' Deserialize JSON string into an instance of Zebra
|
||||
#'
|
||||
#' @description
|
||||
#' Deserialize JSON string into an instance of Zebra
|
||||
#'
|
||||
#' @param input_json the JSON input
|
||||
#' @return the instance of Zebra
|
||||
#' @export
|
||||
fromJSON = function(input_json) {
|
||||
this_object <- jsonlite::fromJSON(input_json)
|
||||
if (!is.null(this_object$`type`)) {
|
||||
self$`type` <- this_object$`type`
|
||||
}
|
||||
if (!is.null(this_object$`className`)) {
|
||||
self$`className` <- this_object$`className`
|
||||
}
|
||||
self
|
||||
},
|
||||
#' To JSON string
|
||||
#'
|
||||
#' @description
|
||||
#' To JSON String
|
||||
#'
|
||||
#' @return Zebra in JSON format
|
||||
#' @export
|
||||
toJSONString = function() {
|
||||
jsoncontent <- c(
|
||||
if (!is.null(self$`type`)) {
|
||||
sprintf(
|
||||
'"type":
|
||||
"%s"
|
||||
',
|
||||
self$`type`
|
||||
)
|
||||
},
|
||||
if (!is.null(self$`className`)) {
|
||||
sprintf(
|
||||
'"className":
|
||||
"%s"
|
||||
',
|
||||
self$`className`
|
||||
)
|
||||
}
|
||||
)
|
||||
jsoncontent <- paste(jsoncontent, collapse = ",")
|
||||
as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = "")))
|
||||
},
|
||||
#' Deserialize JSON string into an instance of Zebra
|
||||
#'
|
||||
#' @description
|
||||
#' Deserialize JSON string into an instance of Zebra
|
||||
#'
|
||||
#' @param input_json the JSON input
|
||||
#' @return the instance of Zebra
|
||||
#' @export
|
||||
fromJSONString = function(input_json) {
|
||||
this_object <- jsonlite::fromJSON(input_json)
|
||||
self$`type` <- this_object$`type`
|
||||
self$`className` <- this_object$`className`
|
||||
self
|
||||
},
|
||||
#' Validate JSON input with respect to Zebra
|
||||
#'
|
||||
#' @description
|
||||
#' Validate JSON input with respect to Zebra and throw an exception if invalid
|
||||
#'
|
||||
#' @param input the JSON input
|
||||
#' @export
|
||||
validateJSON = function(input) {
|
||||
input_json <- jsonlite::fromJSON(input)
|
||||
# check the required field `className`
|
||||
if (!is.null(input_json$`className`)) {
|
||||
stopifnot(is.character(input_json$`className`), length(input_json$`className`) == 1)
|
||||
} else {
|
||||
stop(paste("The JSON input `", input, "` is invalid for Zebra: the required field `className` is missing."))
|
||||
}
|
||||
},
|
||||
#' To string (JSON format)
|
||||
#'
|
||||
#' @description
|
||||
#' To string (JSON format)
|
||||
#'
|
||||
#' @return String representation of Zebra
|
||||
#' @export
|
||||
toString = function() {
|
||||
self$toJSONString()
|
||||
},
|
||||
#' Return true if the values in all fields are valid.
|
||||
#'
|
||||
#' @description
|
||||
#' Return true if the values in all fields are valid.
|
||||
#'
|
||||
#' @return true if the values in all fields are valid.
|
||||
#' @export
|
||||
isValid = function() {
|
||||
# check if the required `className` is null
|
||||
if (is.null(self$`className`)) {
|
||||
return(FALSE)
|
||||
}
|
||||
|
||||
TRUE
|
||||
},
|
||||
#' Return a list of invalid fields (if any).
|
||||
#'
|
||||
#' @description
|
||||
#' Return a list of invalid fields (if any).
|
||||
#'
|
||||
#' @return A list of invalid fields (if any).
|
||||
#' @export
|
||||
getInvalidFields = function() {
|
||||
invalid_fields <- list()
|
||||
# check if the required `className` is null
|
||||
if (is.null(self$`className`)) {
|
||||
invalid_fields["className"] <- "Non-nullable required field `className` cannot be null."
|
||||
}
|
||||
|
||||
invalid_fields
|
||||
}
|
||||
),
|
||||
# Lock the class to prevent modifications to the method or field
|
||||
lock_class = TRUE
|
||||
)
|
||||
|
||||
# Unlock the class to allow modifications of the method or field
|
||||
Zebra$unlock()
|
||||
|
||||
#' Print the object
|
||||
#'
|
||||
#' @description
|
||||
#' Print the object
|
||||
#'
|
||||
#' @export
|
||||
Zebra$set("public", "print", function(...) {
|
||||
print(jsonlite::prettify(self$toJSONString()))
|
||||
invisible(self)
|
||||
})
|
||||
|
||||
# Lock the class to prevent modifications to the method or field
|
||||
Zebra$lock()
|
||||
|
@ -100,6 +100,7 @@ Class | Method | HTTP request | Description
|
||||
- [DanishPig](docs/DanishPig.md)
|
||||
- [Dog](docs/Dog.md)
|
||||
- [DogAllOf](docs/DogAllOf.md)
|
||||
- [Mammal](docs/Mammal.md)
|
||||
- [ModelApiResponse](docs/ModelApiResponse.md)
|
||||
- [NestedOneOf](docs/NestedOneOf.md)
|
||||
- [OneOfPrimitiveTypeTest](docs/OneOfPrimitiveTypeTest.md)
|
||||
@ -110,6 +111,8 @@ Class | Method | HTTP request | Description
|
||||
- [Tag](docs/Tag.md)
|
||||
- [UpdatePetRequest](docs/UpdatePetRequest.md)
|
||||
- [User](docs/User.md)
|
||||
- [Whale](docs/Whale.md)
|
||||
- [Zebra](docs/Zebra.md)
|
||||
|
||||
|
||||
## Documentation for Authorization
|
||||
|
12
samples/client/petstore/R-httr2/docs/Mammal.md
Normal file
12
samples/client/petstore/R-httr2/docs/Mammal.md
Normal file
@ -0,0 +1,12 @@
|
||||
# petstore::Mammal
|
||||
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**hasBaleen** | **character** | | [optional]
|
||||
**hasTeeth** | **character** | | [optional]
|
||||
**className** | **character** | |
|
||||
**type** | **character** | | [optional]
|
||||
|
||||
|
11
samples/client/petstore/R-httr2/docs/Whale.md
Normal file
11
samples/client/petstore/R-httr2/docs/Whale.md
Normal file
@ -0,0 +1,11 @@
|
||||
# petstore::Whale
|
||||
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**hasBaleen** | **character** | | [optional]
|
||||
**hasTeeth** | **character** | | [optional]
|
||||
**className** | **character** | |
|
||||
|
||||
|
10
samples/client/petstore/R-httr2/docs/Zebra.md
Normal file
10
samples/client/petstore/R-httr2/docs/Zebra.md
Normal file
@ -0,0 +1,10 @@
|
||||
# petstore::Zebra
|
||||
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**type** | **character** | | [optional]
|
||||
**className** | **character** | |
|
||||
|
||||
|
34
samples/client/petstore/R-httr2/tests/testthat/test_mammal.R
Normal file
34
samples/client/petstore/R-httr2/tests/testthat/test_mammal.R
Normal file
@ -0,0 +1,34 @@
|
||||
# Automatically generated by openapi-generator (https://openapi-generator.tech)
|
||||
# Please update as you see appropriate
|
||||
|
||||
context("Test Mammal")
|
||||
|
||||
model_instance <- Mammal$new()
|
||||
|
||||
test_that("hasBaleen", {
|
||||
# tests for the property `hasBaleen` (character)
|
||||
|
||||
# uncomment below to test the property
|
||||
#expect_equal(model.instance$`hasBaleen`, "EXPECTED_RESULT")
|
||||
})
|
||||
|
||||
test_that("hasTeeth", {
|
||||
# tests for the property `hasTeeth` (character)
|
||||
|
||||
# uncomment below to test the property
|
||||
#expect_equal(model.instance$`hasTeeth`, "EXPECTED_RESULT")
|
||||
})
|
||||
|
||||
test_that("className", {
|
||||
# tests for the property `className` (character)
|
||||
|
||||
# uncomment below to test the property
|
||||
#expect_equal(model.instance$`className`, "EXPECTED_RESULT")
|
||||
})
|
||||
|
||||
test_that("type", {
|
||||
# tests for the property `type` (character)
|
||||
|
||||
# uncomment below to test the property
|
||||
#expect_equal(model.instance$`type`, "EXPECTED_RESULT")
|
||||
})
|
27
samples/client/petstore/R-httr2/tests/testthat/test_whale.R
Normal file
27
samples/client/petstore/R-httr2/tests/testthat/test_whale.R
Normal file
@ -0,0 +1,27 @@
|
||||
# Automatically generated by openapi-generator (https://openapi-generator.tech)
|
||||
# Please update as you see appropriate
|
||||
|
||||
context("Test Whale")
|
||||
|
||||
model_instance <- Whale$new()
|
||||
|
||||
test_that("hasBaleen", {
|
||||
# tests for the property `hasBaleen` (character)
|
||||
|
||||
# uncomment below to test the property
|
||||
#expect_equal(model.instance$`hasBaleen`, "EXPECTED_RESULT")
|
||||
})
|
||||
|
||||
test_that("hasTeeth", {
|
||||
# tests for the property `hasTeeth` (character)
|
||||
|
||||
# uncomment below to test the property
|
||||
#expect_equal(model.instance$`hasTeeth`, "EXPECTED_RESULT")
|
||||
})
|
||||
|
||||
test_that("className", {
|
||||
# tests for the property `className` (character)
|
||||
|
||||
# uncomment below to test the property
|
||||
#expect_equal(model.instance$`className`, "EXPECTED_RESULT")
|
||||
})
|
20
samples/client/petstore/R-httr2/tests/testthat/test_zebra.R
Normal file
20
samples/client/petstore/R-httr2/tests/testthat/test_zebra.R
Normal file
@ -0,0 +1,20 @@
|
||||
# Automatically generated by openapi-generator (https://openapi-generator.tech)
|
||||
# Please update as you see appropriate
|
||||
|
||||
context("Test Zebra")
|
||||
|
||||
model_instance <- Zebra$new()
|
||||
|
||||
test_that("type", {
|
||||
# tests for the property `type` (character)
|
||||
|
||||
# uncomment below to test the property
|
||||
#expect_equal(model.instance$`type`, "EXPECTED_RESULT")
|
||||
})
|
||||
|
||||
test_that("className", {
|
||||
# tests for the property `className` (character)
|
||||
|
||||
# uncomment below to test the property
|
||||
#expect_equal(model.instance$`className`, "EXPECTED_RESULT")
|
||||
})
|
@ -20,6 +20,7 @@ R/danish_pig.R
|
||||
R/dog.R
|
||||
R/dog_all_of.R
|
||||
R/fake_api.R
|
||||
R/mammal.R
|
||||
R/model_api_response.R
|
||||
R/nested_one_of.R
|
||||
R/one_of_primitive_type_test.R
|
||||
@ -33,6 +34,8 @@ R/tag.R
|
||||
R/update_pet_request.R
|
||||
R/user.R
|
||||
R/user_api.R
|
||||
R/whale.R
|
||||
R/zebra.R
|
||||
README.md
|
||||
docs/AllofTagApiResponse.md
|
||||
docs/Animal.md
|
||||
@ -46,6 +49,7 @@ docs/DanishPig.md
|
||||
docs/Dog.md
|
||||
docs/DogAllOf.md
|
||||
docs/FakeApi.md
|
||||
docs/Mammal.md
|
||||
docs/ModelApiResponse.md
|
||||
docs/NestedOneOf.md
|
||||
docs/OneOfPrimitiveTypeTest.md
|
||||
@ -59,5 +63,7 @@ docs/Tag.md
|
||||
docs/UpdatePetRequest.md
|
||||
docs/User.md
|
||||
docs/UserApi.md
|
||||
docs/Whale.md
|
||||
docs/Zebra.md
|
||||
git_push.sh
|
||||
tests/testthat.R
|
||||
|
@ -25,6 +25,7 @@ export(Category)
|
||||
export(DanishPig)
|
||||
export(Dog)
|
||||
export(DogAllOf)
|
||||
export(Mammal)
|
||||
export(ModelApiResponse)
|
||||
export(NestedOneOf)
|
||||
export(OneOfPrimitiveTypeTest)
|
||||
@ -35,6 +36,8 @@ export(Special)
|
||||
export(Tag)
|
||||
export(UpdatePetRequest)
|
||||
export(User)
|
||||
export(Whale)
|
||||
export(Zebra)
|
||||
|
||||
# APIs
|
||||
export(FakeApi)
|
||||
|
197
samples/client/petstore/R/R/mammal.R
Normal file
197
samples/client/petstore/R/R/mammal.R
Normal file
@ -0,0 +1,197 @@
|
||||
#' @docType class
|
||||
#' @title Mammal
|
||||
#'
|
||||
#' @description Mammal Class
|
||||
#'
|
||||
#' @format An \code{R6Class} generator object
|
||||
#'
|
||||
#' @importFrom R6 R6Class
|
||||
#' @importFrom jsonlite fromJSON toJSON
|
||||
#' @export
|
||||
Mammal <- R6::R6Class(
|
||||
"Mammal",
|
||||
public = list(
|
||||
#' @field actual_instance the object stored in this instance.
|
||||
actual_instance = NULL,
|
||||
#' @field actual_type the type of the object stored in this instance.
|
||||
actual_type = NULL,
|
||||
#' @field one_of a list of types defined in the oneOf schema.
|
||||
one_of = list("Whale", "Zebra"),
|
||||
#' Initialize a new Mammal.
|
||||
#'
|
||||
#' @description
|
||||
#' Initialize a new Mammal.
|
||||
#'
|
||||
#' @param instance an instance of the object defined in the oneOf schemas: "Whale", "Zebra"
|
||||
#' @export
|
||||
initialize = function(instance = NULL) {
|
||||
if (is.null(instance)) {
|
||||
# do nothing
|
||||
} else if (get(class(instance)[[1]], pos = -1)$classname == "Whale") {
|
||||
self$actual_instance <- instance
|
||||
self$actual_type <- "Whale"
|
||||
} else if (get(class(instance)[[1]], pos = -1)$classname == "Zebra") {
|
||||
self$actual_instance <- instance
|
||||
self$actual_type <- "Zebra"
|
||||
} else {
|
||||
stop(paste("Failed to initialize Mammal with oneOf schemas Whale, Zebra. Provided class name: ",
|
||||
get(class(instance)[[1]], pos = -1)$classname))
|
||||
}
|
||||
},
|
||||
#' Deserialize JSON string into an instance of Mammal.
|
||||
#'
|
||||
#' @description
|
||||
#' Deserialize JSON string into an instance of Mammal.
|
||||
#' An alias to the method `fromJSON` .
|
||||
#'
|
||||
#' @param input The input JSON.
|
||||
#' @return An instance of Mammal.
|
||||
#' @export
|
||||
fromJSONString = function(input) {
|
||||
self$fromJSON(input)
|
||||
},
|
||||
#' Deserialize JSON string into an instance of Mammal.
|
||||
#'
|
||||
#' @description
|
||||
#' Deserialize JSON string into an instance of Mammal.
|
||||
#'
|
||||
#' @param input The input JSON.
|
||||
#' @return An instance of Mammal.
|
||||
#' @export
|
||||
fromJSON = function(input) {
|
||||
matched <- 0 # match counter
|
||||
matched_schemas <- list() #names of matched schemas
|
||||
error_messages <- list()
|
||||
instance <- NULL
|
||||
|
||||
Whale_result <- tryCatch({
|
||||
Whale$public_methods$validateJSON(input)
|
||||
Whale_instance <- Whale$new()
|
||||
instance <- Whale_instance$fromJSON(input)
|
||||
instance_type <- "Whale"
|
||||
matched_schemas <- append(matched_schemas, "Whale")
|
||||
matched <- matched + 1
|
||||
},
|
||||
error = function(err) err
|
||||
)
|
||||
|
||||
if (!is.null(Whale_result["error"])) {
|
||||
error_messages <- append(error_messages, Whale_result["message"])
|
||||
}
|
||||
|
||||
Zebra_result <- tryCatch({
|
||||
Zebra$public_methods$validateJSON(input)
|
||||
Zebra_instance <- Zebra$new()
|
||||
instance <- Zebra_instance$fromJSON(input)
|
||||
instance_type <- "Zebra"
|
||||
matched_schemas <- append(matched_schemas, "Zebra")
|
||||
matched <- matched + 1
|
||||
},
|
||||
error = function(err) err
|
||||
)
|
||||
|
||||
if (!is.null(Zebra_result["error"])) {
|
||||
error_messages <- append(error_messages, Zebra_result["message"])
|
||||
}
|
||||
|
||||
if (matched == 1) {
|
||||
# successfully match exactly 1 schema specified in oneOf
|
||||
self$actual_instance <- instance
|
||||
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.")
|
||||
} else {
|
||||
# no match
|
||||
stop(paste("No match found when deserializing the payload into Mammal with oneOf schemas Whale, Zebra. Details: ",
|
||||
paste(error_messages, collapse = ", ")))
|
||||
}
|
||||
|
||||
self
|
||||
},
|
||||
#' Serialize Mammal to JSON string.
|
||||
#'
|
||||
#' @description
|
||||
#' Serialize Mammal to JSON string.
|
||||
#'
|
||||
#' @return JSON string representation of the Mammal.
|
||||
#' @export
|
||||
toJSONString = function() {
|
||||
if (!is.null(self$actual_instance)) {
|
||||
as.character(jsonlite::minify(self$actual_instance$toJSONString()))
|
||||
} else {
|
||||
NULL
|
||||
}
|
||||
},
|
||||
#' Serialize Mammal to JSON.
|
||||
#'
|
||||
#' @description
|
||||
#' Serialize Mammal to JSON.
|
||||
#'
|
||||
#' @return JSON representation of the Mammal.
|
||||
#' @export
|
||||
toJSON = function() {
|
||||
if (!is.null(self$actual_instance)) {
|
||||
self$actual_instance$toJSON()
|
||||
} else {
|
||||
NULL
|
||||
}
|
||||
},
|
||||
#' Validate the input JSON with respect to Mammal.
|
||||
#'
|
||||
#' @description
|
||||
#' Validate the input JSON with respect to Mammal and
|
||||
#' throw exception if invalid.
|
||||
#'
|
||||
#' @param input The input JSON.
|
||||
#' @export
|
||||
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
|
||||
},
|
||||
#' Returns the string representation of the instance.
|
||||
#'
|
||||
#' @description
|
||||
#' Returns the string representation of the instance.
|
||||
#'
|
||||
#' @return The string representation of the instance.
|
||||
#' @export
|
||||
toString = function() {
|
||||
jsoncontent <- c(
|
||||
sprintf('"actual_instance": %s', if (is.null(self$actual_instance)) NULL else self$actual_instance$toJSONString()),
|
||||
sprintf('"actual_type": "%s"', self$actual_type),
|
||||
sprintf('"one_of": "%s"', paste(unlist(self$one_of), collapse = ", "))
|
||||
)
|
||||
jsoncontent <- paste(jsoncontent, collapse = ",")
|
||||
as.character(jsonlite::prettify(paste("{", jsoncontent, "}", sep = "")))
|
||||
}
|
||||
),
|
||||
# Lock the class to prevent modifications to the method or field
|
||||
lock_class = TRUE
|
||||
)
|
||||
|
||||
# Unlock the class to allow modifications of the method or field
|
||||
Mammal$unlock()
|
||||
|
||||
#' Print the object
|
||||
#'
|
||||
#' @description
|
||||
#' Print the object
|
||||
#'
|
||||
#' @export
|
||||
Mammal$set("public", "print", function(...) {
|
||||
print(jsonlite::prettify(self$toJSONString()))
|
||||
invisible(self)
|
||||
})
|
||||
|
||||
# Lock the class to prevent modifications to the method or field
|
||||
Mammal$lock()
|
||||
|
223
samples/client/petstore/R/R/whale.R
Normal file
223
samples/client/petstore/R/R/whale.R
Normal file
@ -0,0 +1,223 @@
|
||||
#' Create a new Whale
|
||||
#'
|
||||
#' @description
|
||||
#' Whale Class
|
||||
#'
|
||||
#' @docType class
|
||||
#' @title Whale
|
||||
#' @description Whale Class
|
||||
#' @format An \code{R6Class} generator object
|
||||
#' @field hasBaleen character [optional]
|
||||
#' @field hasTeeth character [optional]
|
||||
#' @field className character
|
||||
#' @importFrom R6 R6Class
|
||||
#' @importFrom jsonlite fromJSON toJSON
|
||||
#' @export
|
||||
Whale <- R6::R6Class(
|
||||
"Whale",
|
||||
public = list(
|
||||
`hasBaleen` = NULL,
|
||||
`hasTeeth` = NULL,
|
||||
`className` = NULL,
|
||||
#' Initialize a new Whale class.
|
||||
#'
|
||||
#' @description
|
||||
#' Initialize a new Whale class.
|
||||
#'
|
||||
#' @param className className
|
||||
#' @param hasBaleen hasBaleen
|
||||
#' @param hasTeeth hasTeeth
|
||||
#' @param ... Other optional arguments.
|
||||
#' @export
|
||||
initialize = function(
|
||||
`className`, `hasBaleen` = NULL, `hasTeeth` = NULL, ...
|
||||
) {
|
||||
if (!missing(`className`)) {
|
||||
stopifnot(is.character(`className`), length(`className`) == 1)
|
||||
self$`className` <- `className`
|
||||
}
|
||||
if (!is.null(`hasBaleen`)) {
|
||||
stopifnot(is.logical(`hasBaleen`), length(`hasBaleen`) == 1)
|
||||
self$`hasBaleen` <- `hasBaleen`
|
||||
}
|
||||
if (!is.null(`hasTeeth`)) {
|
||||
stopifnot(is.logical(`hasTeeth`), length(`hasTeeth`) == 1)
|
||||
self$`hasTeeth` <- `hasTeeth`
|
||||
}
|
||||
},
|
||||
#' To JSON string
|
||||
#'
|
||||
#' @description
|
||||
#' To JSON String
|
||||
#'
|
||||
#' @return Whale in JSON format
|
||||
#' @export
|
||||
toJSON = function() {
|
||||
WhaleObject <- list()
|
||||
if (!is.null(self$`hasBaleen`)) {
|
||||
WhaleObject[["hasBaleen"]] <-
|
||||
self$`hasBaleen`
|
||||
}
|
||||
if (!is.null(self$`hasTeeth`)) {
|
||||
WhaleObject[["hasTeeth"]] <-
|
||||
self$`hasTeeth`
|
||||
}
|
||||
if (!is.null(self$`className`)) {
|
||||
WhaleObject[["className"]] <-
|
||||
self$`className`
|
||||
}
|
||||
|
||||
WhaleObject
|
||||
},
|
||||
#' Deserialize JSON string into an instance of Whale
|
||||
#'
|
||||
#' @description
|
||||
#' Deserialize JSON string into an instance of Whale
|
||||
#'
|
||||
#' @param input_json the JSON input
|
||||
#' @return the instance of Whale
|
||||
#' @export
|
||||
fromJSON = function(input_json) {
|
||||
this_object <- jsonlite::fromJSON(input_json)
|
||||
if (!is.null(this_object$`hasBaleen`)) {
|
||||
self$`hasBaleen` <- this_object$`hasBaleen`
|
||||
}
|
||||
if (!is.null(this_object$`hasTeeth`)) {
|
||||
self$`hasTeeth` <- this_object$`hasTeeth`
|
||||
}
|
||||
if (!is.null(this_object$`className`)) {
|
||||
self$`className` <- this_object$`className`
|
||||
}
|
||||
self
|
||||
},
|
||||
#' To JSON string
|
||||
#'
|
||||
#' @description
|
||||
#' To JSON String
|
||||
#'
|
||||
#' @return Whale in JSON format
|
||||
#' @export
|
||||
toJSONString = function() {
|
||||
jsoncontent <- c(
|
||||
if (!is.null(self$`hasBaleen`)) {
|
||||
sprintf(
|
||||
'"hasBaleen":
|
||||
%s
|
||||
',
|
||||
tolower(self$`hasBaleen`)
|
||||
)
|
||||
},
|
||||
if (!is.null(self$`hasTeeth`)) {
|
||||
sprintf(
|
||||
'"hasTeeth":
|
||||
%s
|
||||
',
|
||||
tolower(self$`hasTeeth`)
|
||||
)
|
||||
},
|
||||
if (!is.null(self$`className`)) {
|
||||
sprintf(
|
||||
'"className":
|
||||
"%s"
|
||||
',
|
||||
self$`className`
|
||||
)
|
||||
}
|
||||
)
|
||||
jsoncontent <- paste(jsoncontent, collapse = ",")
|
||||
as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = "")))
|
||||
},
|
||||
#' Deserialize JSON string into an instance of Whale
|
||||
#'
|
||||
#' @description
|
||||
#' Deserialize JSON string into an instance of Whale
|
||||
#'
|
||||
#' @param input_json the JSON input
|
||||
#' @return the instance of Whale
|
||||
#' @export
|
||||
fromJSONString = function(input_json) {
|
||||
this_object <- jsonlite::fromJSON(input_json)
|
||||
self$`hasBaleen` <- this_object$`hasBaleen`
|
||||
self$`hasTeeth` <- this_object$`hasTeeth`
|
||||
self$`className` <- this_object$`className`
|
||||
self
|
||||
},
|
||||
#' Validate JSON input with respect to Whale
|
||||
#'
|
||||
#' @description
|
||||
#' Validate JSON input with respect to Whale and throw an exception if invalid
|
||||
#'
|
||||
#' @param input the JSON input
|
||||
#' @export
|
||||
validateJSON = function(input) {
|
||||
input_json <- jsonlite::fromJSON(input)
|
||||
# check the required field `className`
|
||||
if (!is.null(input_json$`className`)) {
|
||||
stopifnot(is.character(input_json$`className`), length(input_json$`className`) == 1)
|
||||
} else {
|
||||
stop(paste("The JSON input `", input, "` is invalid for Whale: the required field `className` is missing."))
|
||||
}
|
||||
},
|
||||
#' To string (JSON format)
|
||||
#'
|
||||
#' @description
|
||||
#' To string (JSON format)
|
||||
#'
|
||||
#' @return String representation of Whale
|
||||
#' @export
|
||||
toString = function() {
|
||||
self$toJSONString()
|
||||
},
|
||||
#' Return true if the values in all fields are valid.
|
||||
#'
|
||||
#' @description
|
||||
#' Return true if the values in all fields are valid.
|
||||
#'
|
||||
#' @return true if the values in all fields are valid.
|
||||
#' @export
|
||||
isValid = function() {
|
||||
# check if the required `className` is null
|
||||
if (is.null(self$`className`)) {
|
||||
return(FALSE)
|
||||
}
|
||||
|
||||
TRUE
|
||||
},
|
||||
#' Return a list of invalid fields (if any).
|
||||
#'
|
||||
#' @description
|
||||
#' Return a list of invalid fields (if any).
|
||||
#'
|
||||
#' @return A list of invalid fields (if any).
|
||||
#' @export
|
||||
getInvalidFields = function() {
|
||||
invalid_fields <- list()
|
||||
# check if the required `className` is null
|
||||
if (is.null(self$`className`)) {
|
||||
invalid_fields["className"] <- "Non-nullable required field `className` cannot be null."
|
||||
}
|
||||
|
||||
invalid_fields
|
||||
}
|
||||
),
|
||||
# Lock the class to prevent modifications to the method or field
|
||||
lock_class = TRUE
|
||||
)
|
||||
|
||||
# Unlock the class to allow modifications of the method or field
|
||||
Whale$unlock()
|
||||
|
||||
#' Print the object
|
||||
#'
|
||||
#' @description
|
||||
#' Print the object
|
||||
#'
|
||||
#' @export
|
||||
Whale$set("public", "print", function(...) {
|
||||
print(jsonlite::prettify(self$toJSONString()))
|
||||
invisible(self)
|
||||
})
|
||||
|
||||
# Lock the class to prevent modifications to the method or field
|
||||
Whale$lock()
|
||||
|
200
samples/client/petstore/R/R/zebra.R
Normal file
200
samples/client/petstore/R/R/zebra.R
Normal file
@ -0,0 +1,200 @@
|
||||
#' Create a new Zebra
|
||||
#'
|
||||
#' @description
|
||||
#' Zebra Class
|
||||
#'
|
||||
#' @docType class
|
||||
#' @title Zebra
|
||||
#' @description Zebra Class
|
||||
#' @format An \code{R6Class} generator object
|
||||
#' @field type character [optional]
|
||||
#' @field className character
|
||||
#' @importFrom R6 R6Class
|
||||
#' @importFrom jsonlite fromJSON toJSON
|
||||
#' @export
|
||||
Zebra <- R6::R6Class(
|
||||
"Zebra",
|
||||
public = list(
|
||||
`type` = NULL,
|
||||
`className` = NULL,
|
||||
#' Initialize a new Zebra class.
|
||||
#'
|
||||
#' @description
|
||||
#' Initialize a new Zebra class.
|
||||
#'
|
||||
#' @param className className
|
||||
#' @param type type
|
||||
#' @param ... Other optional arguments.
|
||||
#' @export
|
||||
initialize = function(
|
||||
`className`, `type` = NULL, ...
|
||||
) {
|
||||
if (!missing(`className`)) {
|
||||
stopifnot(is.character(`className`), length(`className`) == 1)
|
||||
self$`className` <- `className`
|
||||
}
|
||||
if (!is.null(`type`)) {
|
||||
stopifnot(is.character(`type`), length(`type`) == 1)
|
||||
self$`type` <- `type`
|
||||
}
|
||||
},
|
||||
#' To JSON string
|
||||
#'
|
||||
#' @description
|
||||
#' To JSON String
|
||||
#'
|
||||
#' @return Zebra in JSON format
|
||||
#' @export
|
||||
toJSON = function() {
|
||||
ZebraObject <- list()
|
||||
if (!is.null(self$`type`)) {
|
||||
ZebraObject[["type"]] <-
|
||||
self$`type`
|
||||
}
|
||||
if (!is.null(self$`className`)) {
|
||||
ZebraObject[["className"]] <-
|
||||
self$`className`
|
||||
}
|
||||
|
||||
ZebraObject
|
||||
},
|
||||
#' Deserialize JSON string into an instance of Zebra
|
||||
#'
|
||||
#' @description
|
||||
#' Deserialize JSON string into an instance of Zebra
|
||||
#'
|
||||
#' @param input_json the JSON input
|
||||
#' @return the instance of Zebra
|
||||
#' @export
|
||||
fromJSON = function(input_json) {
|
||||
this_object <- jsonlite::fromJSON(input_json)
|
||||
if (!is.null(this_object$`type`)) {
|
||||
self$`type` <- this_object$`type`
|
||||
}
|
||||
if (!is.null(this_object$`className`)) {
|
||||
self$`className` <- this_object$`className`
|
||||
}
|
||||
self
|
||||
},
|
||||
#' To JSON string
|
||||
#'
|
||||
#' @description
|
||||
#' To JSON String
|
||||
#'
|
||||
#' @return Zebra in JSON format
|
||||
#' @export
|
||||
toJSONString = function() {
|
||||
jsoncontent <- c(
|
||||
if (!is.null(self$`type`)) {
|
||||
sprintf(
|
||||
'"type":
|
||||
"%s"
|
||||
',
|
||||
self$`type`
|
||||
)
|
||||
},
|
||||
if (!is.null(self$`className`)) {
|
||||
sprintf(
|
||||
'"className":
|
||||
"%s"
|
||||
',
|
||||
self$`className`
|
||||
)
|
||||
}
|
||||
)
|
||||
jsoncontent <- paste(jsoncontent, collapse = ",")
|
||||
as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = "")))
|
||||
},
|
||||
#' Deserialize JSON string into an instance of Zebra
|
||||
#'
|
||||
#' @description
|
||||
#' Deserialize JSON string into an instance of Zebra
|
||||
#'
|
||||
#' @param input_json the JSON input
|
||||
#' @return the instance of Zebra
|
||||
#' @export
|
||||
fromJSONString = function(input_json) {
|
||||
this_object <- jsonlite::fromJSON(input_json)
|
||||
self$`type` <- this_object$`type`
|
||||
self$`className` <- this_object$`className`
|
||||
self
|
||||
},
|
||||
#' Validate JSON input with respect to Zebra
|
||||
#'
|
||||
#' @description
|
||||
#' Validate JSON input with respect to Zebra and throw an exception if invalid
|
||||
#'
|
||||
#' @param input the JSON input
|
||||
#' @export
|
||||
validateJSON = function(input) {
|
||||
input_json <- jsonlite::fromJSON(input)
|
||||
# check the required field `className`
|
||||
if (!is.null(input_json$`className`)) {
|
||||
stopifnot(is.character(input_json$`className`), length(input_json$`className`) == 1)
|
||||
} else {
|
||||
stop(paste("The JSON input `", input, "` is invalid for Zebra: the required field `className` is missing."))
|
||||
}
|
||||
},
|
||||
#' To string (JSON format)
|
||||
#'
|
||||
#' @description
|
||||
#' To string (JSON format)
|
||||
#'
|
||||
#' @return String representation of Zebra
|
||||
#' @export
|
||||
toString = function() {
|
||||
self$toJSONString()
|
||||
},
|
||||
#' Return true if the values in all fields are valid.
|
||||
#'
|
||||
#' @description
|
||||
#' Return true if the values in all fields are valid.
|
||||
#'
|
||||
#' @return true if the values in all fields are valid.
|
||||
#' @export
|
||||
isValid = function() {
|
||||
# check if the required `className` is null
|
||||
if (is.null(self$`className`)) {
|
||||
return(FALSE)
|
||||
}
|
||||
|
||||
TRUE
|
||||
},
|
||||
#' Return a list of invalid fields (if any).
|
||||
#'
|
||||
#' @description
|
||||
#' Return a list of invalid fields (if any).
|
||||
#'
|
||||
#' @return A list of invalid fields (if any).
|
||||
#' @export
|
||||
getInvalidFields = function() {
|
||||
invalid_fields <- list()
|
||||
# check if the required `className` is null
|
||||
if (is.null(self$`className`)) {
|
||||
invalid_fields["className"] <- "Non-nullable required field `className` cannot be null."
|
||||
}
|
||||
|
||||
invalid_fields
|
||||
}
|
||||
),
|
||||
# Lock the class to prevent modifications to the method or field
|
||||
lock_class = TRUE
|
||||
)
|
||||
|
||||
# Unlock the class to allow modifications of the method or field
|
||||
Zebra$unlock()
|
||||
|
||||
#' Print the object
|
||||
#'
|
||||
#' @description
|
||||
#' Print the object
|
||||
#'
|
||||
#' @export
|
||||
Zebra$set("public", "print", function(...) {
|
||||
print(jsonlite::prettify(self$toJSONString()))
|
||||
invisible(self)
|
||||
})
|
||||
|
||||
# Lock the class to prevent modifications to the method or field
|
||||
Zebra$lock()
|
||||
|
@ -100,6 +100,7 @@ Class | Method | HTTP request | Description
|
||||
- [DanishPig](docs/DanishPig.md)
|
||||
- [Dog](docs/Dog.md)
|
||||
- [DogAllOf](docs/DogAllOf.md)
|
||||
- [Mammal](docs/Mammal.md)
|
||||
- [ModelApiResponse](docs/ModelApiResponse.md)
|
||||
- [NestedOneOf](docs/NestedOneOf.md)
|
||||
- [OneOfPrimitiveTypeTest](docs/OneOfPrimitiveTypeTest.md)
|
||||
@ -110,6 +111,8 @@ Class | Method | HTTP request | Description
|
||||
- [Tag](docs/Tag.md)
|
||||
- [UpdatePetRequest](docs/UpdatePetRequest.md)
|
||||
- [User](docs/User.md)
|
||||
- [Whale](docs/Whale.md)
|
||||
- [Zebra](docs/Zebra.md)
|
||||
|
||||
|
||||
## Documentation for Authorization
|
||||
|
12
samples/client/petstore/R/docs/Mammal.md
Normal file
12
samples/client/petstore/R/docs/Mammal.md
Normal file
@ -0,0 +1,12 @@
|
||||
# petstore::Mammal
|
||||
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**hasBaleen** | **character** | | [optional]
|
||||
**hasTeeth** | **character** | | [optional]
|
||||
**className** | **character** | |
|
||||
**type** | **character** | | [optional]
|
||||
|
||||
|
11
samples/client/petstore/R/docs/Whale.md
Normal file
11
samples/client/petstore/R/docs/Whale.md
Normal file
@ -0,0 +1,11 @@
|
||||
# petstore::Whale
|
||||
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**hasBaleen** | **character** | | [optional]
|
||||
**hasTeeth** | **character** | | [optional]
|
||||
**className** | **character** | |
|
||||
|
||||
|
10
samples/client/petstore/R/docs/Zebra.md
Normal file
10
samples/client/petstore/R/docs/Zebra.md
Normal file
@ -0,0 +1,10 @@
|
||||
# petstore::Zebra
|
||||
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**type** | **character** | | [optional]
|
||||
**className** | **character** | |
|
||||
|
||||
|
34
samples/client/petstore/R/tests/testthat/test_mammal.R
Normal file
34
samples/client/petstore/R/tests/testthat/test_mammal.R
Normal file
@ -0,0 +1,34 @@
|
||||
# Automatically generated by openapi-generator (https://openapi-generator.tech)
|
||||
# Please update as you see appropriate
|
||||
|
||||
context("Test Mammal")
|
||||
|
||||
model_instance <- Mammal$new()
|
||||
|
||||
test_that("hasBaleen", {
|
||||
# tests for the property `hasBaleen` (character)
|
||||
|
||||
# uncomment below to test the property
|
||||
#expect_equal(model.instance$`hasBaleen`, "EXPECTED_RESULT")
|
||||
})
|
||||
|
||||
test_that("hasTeeth", {
|
||||
# tests for the property `hasTeeth` (character)
|
||||
|
||||
# uncomment below to test the property
|
||||
#expect_equal(model.instance$`hasTeeth`, "EXPECTED_RESULT")
|
||||
})
|
||||
|
||||
test_that("className", {
|
||||
# tests for the property `className` (character)
|
||||
|
||||
# uncomment below to test the property
|
||||
#expect_equal(model.instance$`className`, "EXPECTED_RESULT")
|
||||
})
|
||||
|
||||
test_that("type", {
|
||||
# tests for the property `type` (character)
|
||||
|
||||
# uncomment below to test the property
|
||||
#expect_equal(model.instance$`type`, "EXPECTED_RESULT")
|
||||
})
|
27
samples/client/petstore/R/tests/testthat/test_whale.R
Normal file
27
samples/client/petstore/R/tests/testthat/test_whale.R
Normal file
@ -0,0 +1,27 @@
|
||||
# Automatically generated by openapi-generator (https://openapi-generator.tech)
|
||||
# Please update as you see appropriate
|
||||
|
||||
context("Test Whale")
|
||||
|
||||
model_instance <- Whale$new()
|
||||
|
||||
test_that("hasBaleen", {
|
||||
# tests for the property `hasBaleen` (character)
|
||||
|
||||
# uncomment below to test the property
|
||||
#expect_equal(model.instance$`hasBaleen`, "EXPECTED_RESULT")
|
||||
})
|
||||
|
||||
test_that("hasTeeth", {
|
||||
# tests for the property `hasTeeth` (character)
|
||||
|
||||
# uncomment below to test the property
|
||||
#expect_equal(model.instance$`hasTeeth`, "EXPECTED_RESULT")
|
||||
})
|
||||
|
||||
test_that("className", {
|
||||
# tests for the property `className` (character)
|
||||
|
||||
# uncomment below to test the property
|
||||
#expect_equal(model.instance$`className`, "EXPECTED_RESULT")
|
||||
})
|
20
samples/client/petstore/R/tests/testthat/test_zebra.R
Normal file
20
samples/client/petstore/R/tests/testthat/test_zebra.R
Normal file
@ -0,0 +1,20 @@
|
||||
# Automatically generated by openapi-generator (https://openapi-generator.tech)
|
||||
# Please update as you see appropriate
|
||||
|
||||
context("Test Zebra")
|
||||
|
||||
model_instance <- Zebra$new()
|
||||
|
||||
test_that("type", {
|
||||
# tests for the property `type` (character)
|
||||
|
||||
# uncomment below to test the property
|
||||
#expect_equal(model.instance$`type`, "EXPECTED_RESULT")
|
||||
})
|
||||
|
||||
test_that("className", {
|
||||
# tests for the property `className` (character)
|
||||
|
||||
# uncomment below to test the property
|
||||
#expect_equal(model.instance$`className`, "EXPECTED_RESULT")
|
||||
})
|
Loading…
x
Reference in New Issue
Block a user