Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -601,17 +601,25 @@ public String toOperationId(String operationId) {
public ModelsMap postProcessModels(ModelsMap objs) {
for (ModelMap mo : objs.getModels()) {
CodegenModel cm = mo.getModel();
boolean needsExtractSimpleType = false;
for (CodegenProperty var : cm.vars) {
// check to see if base name is an empty string
if ("".equals(var.baseName)) {
LOGGER.debug("Empty baseName `` (empty string) in the model `{}` has been renamed to `empty_string` to avoid compilation errors.", cm.classname);
var.baseName = "empty_string";
}

if (!var.isPrimitiveType) {
needsExtractSimpleType = true;
}

// create extension x-r-doc-type to store the data type in r doc format
var.vendorExtensions.put("x-r-doc-type", constructRdocType(var));
}

// create extension x-r-has-non-primitive-field to indicate whether generated models need special handling for complex types
cm.vendorExtensions.put("x-r-has-non-primitive-field", needsExtractSimpleType);

// apply the same fix, enhancement for allVars
for (CodegenProperty var : cm.allVars) {
// check to see if base name is an empty string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,15 @@
self$`{{name}}`
{{/isPrimitiveType}}
{{^isPrimitiveType}}
lapply(self$`{{name}}`, function(x) x$toSimpleType())
self$extractSimpleType(self$`{{name}}`)
{{/isPrimitiveType}}
{{/isArray}}
{{#isMap}}
{{#isPrimitiveType}}
self$`{{name}}`
{{/isPrimitiveType}}
{{^isPrimitiveType}}
lapply(self$`{{name}}`, function(x) x$toSimpleType())
self$extractSimpleType(self$`{{name}}`)
{{/isPrimitiveType}}
{{/isMap}}
{{/isContainer}}
Expand All @@ -259,7 +259,7 @@
self$`{{name}}`
{{/isPrimitiveType}}
{{^isPrimitiveType}}
self$`{{name}}`$toSimpleType()
self$extractSimpleType(self$`{{name}}`)
{{/isPrimitiveType}}
{{/isContainer}}
}
Expand All @@ -272,6 +272,31 @@
{{/isAdditionalPropertiesTrue}}
return({{classname}}Object)
},
{{#vendorExtensions.x-r-has-non-primitive-field}}

extractSimpleType = function(x) {
if (R6::is.R6(x)) {
return(x$toSimpleType())
} else if (!self$hasNestedR6(x)) {
return(x)
}
lapply(x, self$extractSimpleType)
},

hasNestedR6 = function(x) {
if (R6::is.R6(x)) {
return(TRUE)
}
if (is.list(x)) {
for (item in x) {
if (self$hasNestedR6(item)) {
return(TRUE)
}
}
}
FALSE
},
{{/vendorExtensions.x-r-has-non-primitive-field}}

#' @description
#' Deserialize JSON string into an instance of {{{classname}}}
Expand Down
25 changes: 24 additions & 1 deletion samples/client/echo_api/r/R/default_value.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ DefaultValue <- R6::R6Class(
DefaultValueObject <- list()
if (!is.null(self$`array_string_enum_ref_default`)) {
DefaultValueObject[["array_string_enum_ref_default"]] <-
lapply(self$`array_string_enum_ref_default`, function(x) x$toSimpleType())
self$extractSimpleType(self$`array_string_enum_ref_default`)
}
if (!is.null(self$`array_string_enum_default`)) {
DefaultValueObject[["array_string_enum_default"]] <-
Expand Down Expand Up @@ -152,6 +152,29 @@ DefaultValue <- R6::R6Class(
return(DefaultValueObject)
},

extractSimpleType = function(x) {
if (R6::is.R6(x)) {
return(x$toSimpleType())
} else if (!self$hasNestedR6(x)) {
return(x)
}
lapply(x, self$extractSimpleType)
},

hasNestedR6 = function(x) {
if (R6::is.R6(x)) {
return(TRUE)
}
if (is.list(x)) {
for (item in x) {
if (self$hasNestedR6(item)) {
return(TRUE)
}
}
}
FALSE
},

#' @description
#' Deserialize JSON string into an instance of DefaultValue
#'
Expand Down
27 changes: 25 additions & 2 deletions samples/client/echo_api/r/R/pet.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ Pet <- R6::R6Class(
}
if (!is.null(self$`category`)) {
PetObject[["category"]] <-
self$`category`$toSimpleType()
self$extractSimpleType(self$`category`)
}
if (!is.null(self$`photoUrls`)) {
PetObject[["photoUrls"]] <-
self$`photoUrls`
}
if (!is.null(self$`tags`)) {
PetObject[["tags"]] <-
lapply(self$`tags`, function(x) x$toSimpleType())
self$extractSimpleType(self$`tags`)
}
if (!is.null(self$`status`)) {
PetObject[["status"]] <-
Expand All @@ -132,6 +132,29 @@ Pet <- R6::R6Class(
return(PetObject)
},

extractSimpleType = function(x) {
if (R6::is.R6(x)) {
return(x$toSimpleType())
} else if (!self$hasNestedR6(x)) {
return(x)
}
lapply(x, self$extractSimpleType)
},

hasNestedR6 = function(x) {
if (R6::is.R6(x)) {
return(TRUE)
}
if (is.list(x)) {
for (item in x) {
if (self$hasNestedR6(item)) {
return(TRUE)
}
}
}
FALSE
},

#' @description
#' Deserialize JSON string into an instance of Pet
#'
Expand Down
25 changes: 24 additions & 1 deletion samples/client/petstore/R-httr2-wrapper/R/nested_one_of.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ NestedOneOf <- R6::R6Class(
}
if (!is.null(self$`nested_pig`)) {
NestedOneOfObject[["nested_pig"]] <-
self$`nested_pig`$toSimpleType()
self$extractSimpleType(self$`nested_pig`)
}
for (key in names(self$additional_properties)) {
NestedOneOfObject[[key]] <- self$additional_properties[[key]]
Expand All @@ -93,6 +93,29 @@ NestedOneOf <- R6::R6Class(
return(NestedOneOfObject)
},

extractSimpleType = function(x) {
if (R6::is.R6(x)) {
return(x$toSimpleType())
} else if (!self$hasNestedR6(x)) {
return(x)
}
lapply(x, self$extractSimpleType)
},

hasNestedR6 = function(x) {
if (R6::is.R6(x)) {
return(TRUE)
}
if (is.list(x)) {
for (item in x) {
if (self$hasNestedR6(item)) {
return(TRUE)
}
}
}
FALSE
},

#' @description
#' Deserialize JSON string into an instance of NestedOneOf
#'
Expand Down
27 changes: 25 additions & 2 deletions samples/client/petstore/R-httr2-wrapper/R/pet.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Pet <- R6::R6Class(
}
if (!is.null(self$`category`)) {
PetObject[["category"]] <-
self$`category`$toSimpleType()
self$extractSimpleType(self$`category`)
}
if (!is.null(self$`name`)) {
PetObject[["name"]] <-
Expand All @@ -133,7 +133,7 @@ Pet <- R6::R6Class(
}
if (!is.null(self$`tags`)) {
PetObject[["tags"]] <-
lapply(self$`tags`, function(x) x$toSimpleType())
self$extractSimpleType(self$`tags`)
}
if (!is.null(self$`status`)) {
PetObject[["status"]] <-
Expand All @@ -146,6 +146,29 @@ Pet <- R6::R6Class(
return(PetObject)
},

extractSimpleType = function(x) {
if (R6::is.R6(x)) {
return(x$toSimpleType())
} else if (!self$hasNestedR6(x)) {
return(x)
}
lapply(x, self$extractSimpleType)
},

hasNestedR6 = function(x) {
if (R6::is.R6(x)) {
return(TRUE)
}
if (is.list(x)) {
for (item in x) {
if (self$hasNestedR6(item)) {
return(TRUE)
}
}
}
FALSE
},

#' @description
#' Deserialize JSON string into an instance of Pet
#'
Expand Down
25 changes: 24 additions & 1 deletion samples/client/petstore/R-httr2-wrapper/R/update_pet_request.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ UpdatePetRequest <- R6::R6Class(
UpdatePetRequestObject <- list()
if (!is.null(self$`jsonData`)) {
UpdatePetRequestObject[["jsonData"]] <-
self$`jsonData`$toSimpleType()
self$extractSimpleType(self$`jsonData`)
}
if (!is.null(self$`binaryDataN2Information`)) {
UpdatePetRequestObject[["binaryDataN2Information"]] <-
Expand All @@ -90,6 +90,29 @@ UpdatePetRequest <- R6::R6Class(
return(UpdatePetRequestObject)
},

extractSimpleType = function(x) {
if (R6::is.R6(x)) {
return(x$toSimpleType())
} else if (!self$hasNestedR6(x)) {
return(x)
}
lapply(x, self$extractSimpleType)
},

hasNestedR6 = function(x) {
if (R6::is.R6(x)) {
return(TRUE)
}
if (is.list(x)) {
for (item in x) {
if (self$hasNestedR6(item)) {
return(TRUE)
}
}
}
FALSE
},

#' @description
#' Deserialize JSON string into an instance of UpdatePetRequest
#'
Expand Down
25 changes: 24 additions & 1 deletion samples/client/petstore/R-httr2/R/nested_one_of.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,34 @@ NestedOneOf <- R6::R6Class(
}
if (!is.null(self$`nested_pig`)) {
NestedOneOfObject[["nested_pig"]] <-
self$`nested_pig`$toSimpleType()
self$extractSimpleType(self$`nested_pig`)
}
return(NestedOneOfObject)
},

extractSimpleType = function(x) {
if (R6::is.R6(x)) {
return(x$toSimpleType())
} else if (!self$hasNestedR6(x)) {
return(x)
}
lapply(x, self$extractSimpleType)
},

hasNestedR6 = function(x) {
if (R6::is.R6(x)) {
return(TRUE)
}
if (is.list(x)) {
for (item in x) {
if (self$hasNestedR6(item)) {
return(TRUE)
}
}
}
FALSE
},

#' @description
#' Deserialize JSON string into an instance of NestedOneOf
#'
Expand Down
27 changes: 25 additions & 2 deletions samples/client/petstore/R-httr2/R/pet.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Pet <- R6::R6Class(
}
if (!is.null(self$`category`)) {
PetObject[["category"]] <-
self$`category`$toSimpleType()
self$extractSimpleType(self$`category`)
}
if (!is.null(self$`name`)) {
PetObject[["name"]] <-
Expand All @@ -123,7 +123,7 @@ Pet <- R6::R6Class(
}
if (!is.null(self$`tags`)) {
PetObject[["tags"]] <-
lapply(self$`tags`, function(x) x$toSimpleType())
self$extractSimpleType(self$`tags`)
}
if (!is.null(self$`status`)) {
PetObject[["status"]] <-
Expand All @@ -132,6 +132,29 @@ Pet <- R6::R6Class(
return(PetObject)
},

extractSimpleType = function(x) {
if (R6::is.R6(x)) {
return(x$toSimpleType())
} else if (!self$hasNestedR6(x)) {
return(x)
}
lapply(x, self$extractSimpleType)
},

hasNestedR6 = function(x) {
if (R6::is.R6(x)) {
return(TRUE)
}
if (is.list(x)) {
for (item in x) {
if (self$hasNestedR6(item)) {
return(TRUE)
}
}
}
FALSE
},

#' @description
#' Deserialize JSON string into an instance of Pet
#'
Expand Down
Loading
Loading