Skip to content

Commit ace75e5

Browse files
committed
only include extractor methods when they are needed
1 parent eaf6590 commit ace75e5

65 files changed

Lines changed: 11 additions & 1387 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RClientCodegen.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,17 +601,25 @@ public String toOperationId(String operationId) {
601601
public ModelsMap postProcessModels(ModelsMap objs) {
602602
for (ModelMap mo : objs.getModels()) {
603603
CodegenModel cm = mo.getModel();
604+
boolean needsExtractSimpleType = false;
604605
for (CodegenProperty var : cm.vars) {
605606
// check to see if base name is an empty string
606607
if ("".equals(var.baseName)) {
607608
LOGGER.debug("Empty baseName `` (empty string) in the model `{}` has been renamed to `empty_string` to avoid compilation errors.", cm.classname);
608609
var.baseName = "empty_string";
609610
}
610611

612+
if (!var.isPrimitiveType) {
613+
needsExtractSimpleType = true;
614+
}
615+
611616
// create extension x-r-doc-type to store the data type in r doc format
612617
var.vendorExtensions.put("x-r-doc-type", constructRdocType(var));
613618
}
614619

620+
// create extension x-r-has-non-primitive-field to indicate whether generated models need special handling for complex types
621+
cm.vendorExtensions.put("x-r-has-non-primitive-field", needsExtractSimpleType);
622+
615623
// apply the same fix, enhancement for allVars
616624
for (CodegenProperty var : cm.allVars) {
617625
// check to see if base name is an empty string

modules/openapi-generator/src/main/resources/r/modelGeneric.mustache

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@
273273
return({{classname}}Object)
274274
},
275275
276-
extractSimpleType = function(x) {
276+
{{#vendorExtensions.x-r-has-non-primitive-field}}
277+
extractSimpleType = function(x) git{
277278
if (R6::is.R6(x)) {
278279
return(x$toSimpleType())
279280
} else if (!self$hasNestedR6(x)) {
@@ -295,6 +296,7 @@
295296
}
296297
FALSE
297298
},
299+
{{/vendorExtensions.x-r-has-non-primitive-field}}
298300
299301
#' @description
300302
#' Deserialize JSON string into an instance of {{{classname}}}

samples/client/echo_api/r/R/bird.R

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,28 +81,6 @@ Bird <- R6::R6Class(
8181
return(BirdObject)
8282
},
8383

84-
extractSimpleType = function(x) {
85-
if (R6::is.R6(x)) {
86-
return(x$toSimpleType())
87-
} else if (!self$hasNestedR6(x)) {
88-
return(x)
89-
}
90-
lapply(x, self$extractSimpleType)
91-
},
92-
93-
hasNestedR6 = function(x) {
94-
if (R6::is.R6(x)) {
95-
return(TRUE)
96-
}
97-
if (is.list(x)) {
98-
for (item in x) {
99-
if (self$hasNestedR6(item)) {
100-
return(TRUE)
101-
}
102-
}
103-
}
104-
FALSE
105-
},
10684

10785
#' @description
10886
#' Deserialize JSON string into an instance of Bird

samples/client/echo_api/r/R/category.R

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,28 +81,6 @@ Category <- R6::R6Class(
8181
return(CategoryObject)
8282
},
8383

84-
extractSimpleType = function(x) {
85-
if (R6::is.R6(x)) {
86-
return(x$toSimpleType())
87-
} else if (!self$hasNestedR6(x)) {
88-
return(x)
89-
}
90-
lapply(x, self$extractSimpleType)
91-
},
92-
93-
hasNestedR6 = function(x) {
94-
if (R6::is.R6(x)) {
95-
return(TRUE)
96-
}
97-
if (is.list(x)) {
98-
for (item in x) {
99-
if (self$hasNestedR6(item)) {
100-
return(TRUE)
101-
}
102-
}
103-
}
104-
FALSE
105-
},
10684

10785
#' @description
10886
#' Deserialize JSON string into an instance of Category

samples/client/echo_api/r/R/data_query.R

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -120,28 +120,6 @@ DataQuery <- R6::R6Class(
120120
return(DataQueryObject)
121121
},
122122

123-
extractSimpleType = function(x) {
124-
if (R6::is.R6(x)) {
125-
return(x$toSimpleType())
126-
} else if (!self$hasNestedR6(x)) {
127-
return(x)
128-
}
129-
lapply(x, self$extractSimpleType)
130-
},
131-
132-
hasNestedR6 = function(x) {
133-
if (R6::is.R6(x)) {
134-
return(TRUE)
135-
}
136-
if (is.list(x)) {
137-
for (item in x) {
138-
if (self$hasNestedR6(item)) {
139-
return(TRUE)
140-
}
141-
}
142-
}
143-
FALSE
144-
},
145123

146124
#' @description
147125
#' Deserialize JSON string into an instance of DataQuery

samples/client/echo_api/r/R/number_properties_only.R

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -91,28 +91,6 @@ NumberPropertiesOnly <- R6::R6Class(
9191
return(NumberPropertiesOnlyObject)
9292
},
9393

94-
extractSimpleType = function(x) {
95-
if (R6::is.R6(x)) {
96-
return(x$toSimpleType())
97-
} else if (!self$hasNestedR6(x)) {
98-
return(x)
99-
}
100-
lapply(x, self$extractSimpleType)
101-
},
102-
103-
hasNestedR6 = function(x) {
104-
if (R6::is.R6(x)) {
105-
return(TRUE)
106-
}
107-
if (is.list(x)) {
108-
for (item in x) {
109-
if (self$hasNestedR6(item)) {
110-
return(TRUE)
111-
}
112-
}
113-
}
114-
FALSE
115-
},
11694

11795
#' @description
11896
#' Deserialize JSON string into an instance of NumberPropertiesOnly

samples/client/echo_api/r/R/query.R

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -80,28 +80,6 @@ Query <- R6::R6Class(
8080
return(QueryObject)
8181
},
8282

83-
extractSimpleType = function(x) {
84-
if (R6::is.R6(x)) {
85-
return(x$toSimpleType())
86-
} else if (!self$hasNestedR6(x)) {
87-
return(x)
88-
}
89-
lapply(x, self$extractSimpleType)
90-
},
91-
92-
hasNestedR6 = function(x) {
93-
if (R6::is.R6(x)) {
94-
return(TRUE)
95-
}
96-
if (is.list(x)) {
97-
for (item in x) {
98-
if (self$hasNestedR6(item)) {
99-
return(TRUE)
100-
}
101-
}
102-
}
103-
FALSE
104-
},
10583

10684
#' @description
10785
#' Deserialize JSON string into an instance of Query

samples/client/echo_api/r/R/tag.R

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,28 +81,6 @@ Tag <- R6::R6Class(
8181
return(TagObject)
8282
},
8383

84-
extractSimpleType = function(x) {
85-
if (R6::is.R6(x)) {
86-
return(x$toSimpleType())
87-
} else if (!self$hasNestedR6(x)) {
88-
return(x)
89-
}
90-
lapply(x, self$extractSimpleType)
91-
},
92-
93-
hasNestedR6 = function(x) {
94-
if (R6::is.R6(x)) {
95-
return(TRUE)
96-
}
97-
if (is.list(x)) {
98-
for (item in x) {
99-
if (self$hasNestedR6(item)) {
100-
return(TRUE)
101-
}
102-
}
103-
}
104-
FALSE
105-
},
10684

10785
#' @description
10886
#' Deserialize JSON string into an instance of Tag

samples/client/echo_api/r/R/test_form_object_multipart_request_marker.R

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,28 +68,6 @@ TestFormObjectMultipartRequestMarker <- R6::R6Class(
6868
return(TestFormObjectMultipartRequestMarkerObject)
6969
},
7070

71-
extractSimpleType = function(x) {
72-
if (R6::is.R6(x)) {
73-
return(x$toSimpleType())
74-
} else if (!self$hasNestedR6(x)) {
75-
return(x)
76-
}
77-
lapply(x, self$extractSimpleType)
78-
},
79-
80-
hasNestedR6 = function(x) {
81-
if (R6::is.R6(x)) {
82-
return(TRUE)
83-
}
84-
if (is.list(x)) {
85-
for (item in x) {
86-
if (self$hasNestedR6(item)) {
87-
return(TRUE)
88-
}
89-
}
90-
}
91-
FALSE
92-
},
9371

9472
#' @description
9573
#' Deserialize JSON string into an instance of TestFormObjectMultipartRequestMarker

samples/client/echo_api/r/R/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.R

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -107,28 +107,6 @@ TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter <- R6::R6Clas
107107
return(TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameterObject)
108108
},
109109

110-
extractSimpleType = function(x) {
111-
if (R6::is.R6(x)) {
112-
return(x$toSimpleType())
113-
} else if (!self$hasNestedR6(x)) {
114-
return(x)
115-
}
116-
lapply(x, self$extractSimpleType)
117-
},
118-
119-
hasNestedR6 = function(x) {
120-
if (R6::is.R6(x)) {
121-
return(TRUE)
122-
}
123-
if (is.list(x)) {
124-
for (item in x) {
125-
if (self$hasNestedR6(item)) {
126-
return(TRUE)
127-
}
128-
}
129-
}
130-
FALSE
131-
},
132110

133111
#' @description
134112
#' Deserialize JSON string into an instance of TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter

0 commit comments

Comments
 (0)