From ff87d336f7f74092c4ae9f4b8191746ea301f859 Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Mon, 18 Nov 2019 23:56:00 -0500 Subject: [PATCH 01/26] wip: fix documentation tags --- .../src/main/resources/r/api.mustache | 12 ++++++------ .../src/main/resources/r/model.mustache | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/r/api.mustache b/modules/openapi-generator/src/main/resources/r/api.mustache index 0fc38a78916b..a6671da77630 100644 --- a/modules/openapi-generator/src/main/resources/r/api.mustache +++ b/modules/openapi-generator/src/main/resources/r/api.mustache @@ -23,19 +23,19 @@ {{#isListContainer}} {{#items}} {{#isPrimitiveType}} -#' \item \emph{ @param } {{paramName}} list( {{dataType}} ) +#' \item \emph{ @param } {{paramName}} {{dataType}} {{/isPrimitiveType}} {{^isPrimitiveType}} -#' \item \emph{ @param } {{paramName}} list( \link[{{packageName}}:{{baseType}}]{ {{dataType}} } ) +#' \item \emph{ @param } {{paramName}} \link{{=<% %>=}}{<%dataType%>}<%={{ }}=%> {{/isPrimitiveType}} {{/items}} {{/isListContainer}} {{#isMapContainer}} {{#isPrimitiveType}} -#' \item \emph{ @param } {{paramName}} named list( {{dataType}} ) +#' \item \emph{ @param } {{paramName}} named {{dataType}} {{/isPrimitiveType}} {{^isPrimitiveType}} -#' \item \emph{ @param } {{paramName}} named list( \link[{{packageName}}:{{baseType}}]{ {{dataType}} } ) +#' \item \emph{ @param } {{paramName}} named \link{{=<% %>=}}{<%dataType%>}<%={{ }}=%> {{/isPrimitiveType}} {{/isMapContainer}} {{/isContainer}} @@ -44,14 +44,14 @@ #' \item \emph{ @param } {{paramName}} {{dataType}} {{/isPrimitiveType}} {{^isPrimitiveType}} -#' \item \emph{ @param } {{paramName}} \link[{{packageName}}:{{baseType}}]{ {{dataType}} } +#' \item \emph{ @param } {{paramName}} \link{{=<% %>=}}{<%dataType%>}<%={{ }}=%> {{/isPrimitiveType}} {{/isContainer}} {{/isEnum}} {{/allParams}} {{#returnType}} {{^returnTypeIsPrimitive}} -#' \item \emph{ @returnType } \link[{{packageName}}:{{returnBaseType}}]{ {{#returnContainer}}{{#isListContainer}}list({{returnBaseType}}){{/isListContainer}}{{#isMapContainer}}named list({{returnBaseType}}){{/isMapContainer}}{{/returnContainer}}{{^returnContainer}}{{returnType}}{{/returnContainer}} } \cr +#' \item \emph{ @returnType } \link{{=<% %>=}}{<%#returnContainer%><%={{ }}=%>{{#isListContainer}}{{returnBaseType}}{{/isListContainer}}{{#isMapContainer}}named list({{returnBaseType}}){{/isMapContainer}}{{/returnContainer}}{{^returnContainer}}{{returnType}}{{=<% %>=}}<%/returnContainer%>}<%={{ }}=%> \cr {{/returnTypeIsPrimitive}} {{/returnType}} #' diff --git a/modules/openapi-generator/src/main/resources/r/model.mustache b/modules/openapi-generator/src/main/resources/r/model.mustache index ee20e432e742..0764af5c67dc 100644 --- a/modules/openapi-generator/src/main/resources/r/model.mustache +++ b/modules/openapi-generator/src/main/resources/r/model.mustache @@ -6,7 +6,7 @@ #' @description {{classname}} Class #' @format An \code{R6Class} generator object {{#vars}} -#' @field {{baseName}} {{title}} {{^isPrimitiveType}} \link[{{packageName}}:{{complexType}}]{ {{/isPrimitiveType}} {{#isContainer}} {{#isListContainer}}list({{#items}}{{dataType}}{{/items}}){{/isListContainer}}{{#isMapContainer}}named list({{#items}}{{dataType}}{{/items}}){{/isMapContainer}} {{/isContainer}}{{^isContainer}}{{dataType}}{{/isContainer}} {{^isPrimitiveType}} } {{/isPrimitiveType}} {{^required}}[optional]{{/required}} +#' @field {{baseName}} {{title}} {{^isPrimitiveType}} \link[{{packageName}}]{{=<% %>=}}{<%/isPrimitiveType%><%={{ }}=%>{{#isContainer}}{{#isListContainer}}{{#items}}{{dataType}}{{/items}}{{/isListContainer}}{{#isMapContainer}}named list({{#items}}{{dataType}}{{/items}}){{/isMapContainer}}{{/isContainer}}{{^isContainer}}{{dataType}}{{/isContainer}}{{=<% %>=}}<%^isPrimitiveType%><%={{ }}=%>}{{/isPrimitiveType}} {{^required}}[optional]{{/required}} #' {{/vars}} #' From 34350d7413e0b2cd51c6b887bc1d931ad94c17b4 Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Mon, 18 Nov 2019 23:56:32 -0500 Subject: [PATCH 02/26] update model.mustache --- modules/openapi-generator/src/main/resources/r/model.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/r/model.mustache b/modules/openapi-generator/src/main/resources/r/model.mustache index 0764af5c67dc..bfc08cd6ae3c 100644 --- a/modules/openapi-generator/src/main/resources/r/model.mustache +++ b/modules/openapi-generator/src/main/resources/r/model.mustache @@ -6,7 +6,7 @@ #' @description {{classname}} Class #' @format An \code{R6Class} generator object {{#vars}} -#' @field {{baseName}} {{title}} {{^isPrimitiveType}} \link[{{packageName}}]{{=<% %>=}}{<%/isPrimitiveType%><%={{ }}=%>{{#isContainer}}{{#isListContainer}}{{#items}}{{dataType}}{{/items}}{{/isListContainer}}{{#isMapContainer}}named list({{#items}}{{dataType}}{{/items}}){{/isMapContainer}}{{/isContainer}}{{^isContainer}}{{dataType}}{{/isContainer}}{{=<% %>=}}<%^isPrimitiveType%><%={{ }}=%>}{{/isPrimitiveType}} {{^required}}[optional]{{/required}} +#' @field {{baseName}} {{title}} {{^isPrimitiveType}} \link{{=<% %>=}}{<%/isPrimitiveType%><%={{ }}=%>{{#isContainer}}{{#isListContainer}}{{#items}}{{dataType}}{{/items}}{{/isListContainer}}{{#isMapContainer}}named list({{#items}}{{dataType}}{{/items}}){{/isMapContainer}}{{/isContainer}}{{^isContainer}}{{dataType}}{{/isContainer}}{{=<% %>=}}<%^isPrimitiveType%><%={{ }}=%>}{{/isPrimitiveType}} {{^required}}[optional]{{/required}} #' {{/vars}} #' From 0ec4e2203cd623dd2d21c52c1f2aacb38c950cc6 Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Wed, 20 Nov 2019 18:01:34 -0500 Subject: [PATCH 03/26] update template for documentation --- .../src/main/resources/r/api.mustache | 12 ++++++------ .../src/main/resources/r/model.mustache | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/r/api.mustache b/modules/openapi-generator/src/main/resources/r/api.mustache index a6671da77630..b1b684a38f98 100644 --- a/modules/openapi-generator/src/main/resources/r/api.mustache +++ b/modules/openapi-generator/src/main/resources/r/api.mustache @@ -23,25 +23,25 @@ {{#isListContainer}} {{#items}} {{#isPrimitiveType}} -#' \item \emph{ @param } {{paramName}} {{dataType}} +#' \item \emph{ @param } {{paramName}} list {{dataType}} {{/isPrimitiveType}} {{^isPrimitiveType}} -#' \item \emph{ @param } {{paramName}} \link{{=<% %>=}}{<%dataType%>}<%={{ }}=%> +#' \item \emph{ @param } {{paramName}} \link{{=<% %>=}}{<%dataType%>}<%={{ }}=%> list() {{/isPrimitiveType}} {{/items}} {{/isListContainer}} {{#isMapContainer}} {{#isPrimitiveType}} -#' \item \emph{ @param } {{paramName}} named {{dataType}} +#' \item \emph{ @param } {{paramName}} {{dataType}} named list() {{/isPrimitiveType}} {{^isPrimitiveType}} -#' \item \emph{ @param } {{paramName}} named \link{{=<% %>=}}{<%dataType%>}<%={{ }}=%> +#' \item \emph{ @param } {{paramName}} \link{{=<% %>=}}{<%dataType%>}<%={{ }}=%> named list() {{/isPrimitiveType}} {{/isMapContainer}} {{/isContainer}} {{^isContainer}} {{#isPrimitiveType}} -#' \item \emph{ @param } {{paramName}} {{dataType}} +#' \item \emph{ @param } {{paramName}} {{dataType}} list() {{/isPrimitiveType}} {{^isPrimitiveType}} #' \item \emph{ @param } {{paramName}} \link{{=<% %>=}}{<%dataType%>}<%={{ }}=%> @@ -51,7 +51,7 @@ {{/allParams}} {{#returnType}} {{^returnTypeIsPrimitive}} -#' \item \emph{ @returnType } \link{{=<% %>=}}{<%#returnContainer%><%={{ }}=%>{{#isListContainer}}{{returnBaseType}}{{/isListContainer}}{{#isMapContainer}}named list({{returnBaseType}}){{/isMapContainer}}{{/returnContainer}}{{^returnContainer}}{{returnType}}{{=<% %>=}}<%/returnContainer%>}<%={{ }}=%> \cr +#' \item \emph{ @returnType } \link{{=<% %>=}}{<%returnType%>}<%={{ }}=%> \cr {{/returnTypeIsPrimitive}} {{/returnType}} #' diff --git a/modules/openapi-generator/src/main/resources/r/model.mustache b/modules/openapi-generator/src/main/resources/r/model.mustache index bfc08cd6ae3c..9771e127fce5 100644 --- a/modules/openapi-generator/src/main/resources/r/model.mustache +++ b/modules/openapi-generator/src/main/resources/r/model.mustache @@ -6,7 +6,7 @@ #' @description {{classname}} Class #' @format An \code{R6Class} generator object {{#vars}} -#' @field {{baseName}} {{title}} {{^isPrimitiveType}} \link{{=<% %>=}}{<%/isPrimitiveType%><%={{ }}=%>{{#isContainer}}{{#isListContainer}}{{#items}}{{dataType}}{{/items}}{{/isListContainer}}{{#isMapContainer}}named list({{#items}}{{dataType}}{{/items}}){{/isMapContainer}}{{/isContainer}}{{^isContainer}}{{dataType}}{{/isContainer}}{{=<% %>=}}<%^isPrimitiveType%><%={{ }}=%>}{{/isPrimitiveType}} {{^required}}[optional]{{/required}} +#' @field {{baseName}} {{title}} {{^isPrimitiveType}} \link{{=<% %>=}}{<%/isPrimitiveType%><%={{ }}=%>{{#isContainer}}{{#isListContainer}}{{#items}}{{dataType}}{{/items}}{{/isListContainer}}{{#isMapContainer}}{{#items}}{{dataType}}{{/items}}{{/isMapContainer}}{{/isContainer}}{{^isContainer}}{{dataType}}{{/isContainer}}{{=<% %>=}}<%^isPrimitiveType%><%={{ }}=%>}{{/isPrimitiveType}} {{^required}}[optional]{{/required}} #' {{/vars}} #' From 794306cb1f3e581892133084eca8deb4a56c0432 Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Wed, 20 Nov 2019 19:49:26 -0500 Subject: [PATCH 04/26] update mustache templates --- .../src/main/resources/r/api.mustache | 12 ++++++------ .../src/main/resources/r/model.mustache | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/r/api.mustache b/modules/openapi-generator/src/main/resources/r/api.mustache index b1b684a38f98..374ec36a40c9 100644 --- a/modules/openapi-generator/src/main/resources/r/api.mustache +++ b/modules/openapi-generator/src/main/resources/r/api.mustache @@ -23,25 +23,25 @@ {{#isListContainer}} {{#items}} {{#isPrimitiveType}} -#' \item \emph{ @param } {{paramName}} list {{dataType}} +#' \item \emph{ @param } {{paramName}} list( {{dataType}} ) {{/isPrimitiveType}} {{^isPrimitiveType}} -#' \item \emph{ @param } {{paramName}} \link{{=<% %>=}}{<%dataType%>}<%={{ }}=%> list() +#' \item \emph{ @param } {{paramName}} list( \link{{=<% %>=}}{<%dataType%>}<%={{ }}=%> ) {{/isPrimitiveType}} {{/items}} {{/isListContainer}} {{#isMapContainer}} {{#isPrimitiveType}} -#' \item \emph{ @param } {{paramName}} {{dataType}} named list() +#' \item \emph{ @param } {{paramName}} named list( {{dataType}} ) {{/isPrimitiveType}} {{^isPrimitiveType}} -#' \item \emph{ @param } {{paramName}} \link{{=<% %>=}}{<%dataType%>}<%={{ }}=%> named list() +#' \item \emph{ @param } {{paramName}} named list( \link{{=<% %>=}}{<%dataType%>}<%={{ }}=%> ) {{/isPrimitiveType}} {{/isMapContainer}} {{/isContainer}} {{^isContainer}} {{#isPrimitiveType}} -#' \item \emph{ @param } {{paramName}} {{dataType}} list() +#' \item \emph{ @param } {{paramName}} {{dataType}} {{/isPrimitiveType}} {{^isPrimitiveType}} #' \item \emph{ @param } {{paramName}} \link{{=<% %>=}}{<%dataType%>}<%={{ }}=%> @@ -51,7 +51,7 @@ {{/allParams}} {{#returnType}} {{^returnTypeIsPrimitive}} -#' \item \emph{ @returnType } \link{{=<% %>=}}{<%returnType%>}<%={{ }}=%> \cr +#' \item \emph{ @returnType } {{#isListContainer}}list( {{/isListContainer}}{{#isMapContainer}}named list( {{/isMapContainer}}\link{{=<% %>=}}{<%#returnContainer%><%returnBaseType%><%/returnContainer%><%^returnContainer%><%returnType%><%/returnContainer%>}<%={{ }}=%>{{#isListContainer}} ){{/isListContainer}}{{#isMapContainer}} ){{/isMapContainer}} \cr {{/returnTypeIsPrimitive}} {{/returnType}} #' diff --git a/modules/openapi-generator/src/main/resources/r/model.mustache b/modules/openapi-generator/src/main/resources/r/model.mustache index 9771e127fce5..48dd83a26fd9 100644 --- a/modules/openapi-generator/src/main/resources/r/model.mustache +++ b/modules/openapi-generator/src/main/resources/r/model.mustache @@ -6,7 +6,7 @@ #' @description {{classname}} Class #' @format An \code{R6Class} generator object {{#vars}} -#' @field {{baseName}} {{title}} {{^isPrimitiveType}} \link{{=<% %>=}}{<%/isPrimitiveType%><%={{ }}=%>{{#isContainer}}{{#isListContainer}}{{#items}}{{dataType}}{{/items}}{{/isListContainer}}{{#isMapContainer}}{{#items}}{{dataType}}{{/items}}{{/isMapContainer}}{{/isContainer}}{{^isContainer}}{{dataType}}{{/isContainer}}{{=<% %>=}}<%^isPrimitiveType%><%={{ }}=%>}{{/isPrimitiveType}} {{^required}}[optional]{{/required}} +#' @field {{baseName}} {{title}} {{#isPrimitiveType}} {{#isContainer}}{{#isListContainer}}list({{#items}}{{dataType}}{{/items}}){{/isListContainer}}{{#isMapContainer}}named list({{#items}}{{dataType}}{{/items}}){{/isMapContainer}}{{/isContainer}} {{^isContainer}}{{dataType}}{{/isContainer}} {{/isPrimitiveType}} {{^isPrimitiveType}} \link{{=<% %>=}}{<%dataType%>}<%={{ }}=%>{{/isPrimitiveType}} {{^required}}[optional]{{/required}} #' {{/vars}} #' From 95e9a9f967c9558788b7ebc5a5f66794049f89bf Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Thu, 21 Nov 2019 09:10:08 -0500 Subject: [PATCH 05/26] update mustache templates --- modules/openapi-generator/src/main/resources/r/api.mustache | 2 +- modules/openapi-generator/src/main/resources/r/model.mustache | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/r/api.mustache b/modules/openapi-generator/src/main/resources/r/api.mustache index 374ec36a40c9..faae7a57b7fe 100644 --- a/modules/openapi-generator/src/main/resources/r/api.mustache +++ b/modules/openapi-generator/src/main/resources/r/api.mustache @@ -51,7 +51,7 @@ {{/allParams}} {{#returnType}} {{^returnTypeIsPrimitive}} -#' \item \emph{ @returnType } {{#isListContainer}}list( {{/isListContainer}}{{#isMapContainer}}named list( {{/isMapContainer}}\link{{=<% %>=}}{<%#returnContainer%><%returnBaseType%><%/returnContainer%><%^returnContainer%><%returnType%><%/returnContainer%>}<%={{ }}=%>{{#isListContainer}} ){{/isListContainer}}{{#isMapContainer}} ){{/isMapContainer}} \cr +#' \item \emph{ @returnType } {{#returnContainer}}{{#isListContainer}}list( {{/isListContainer}}{{#isMapContainer}}named list( {{/isMapContainer}}{{/returnContainer}}\link{{=<% %>=}}{<%#returnContainer%><%={{ }}=%>{{returnBaseType}}{{/returnContainer}}{{^returnContainer}}{{returnType}}{{=<% %>=}}<%/returnContainer%>}<%={{ }}=%>{{#returnContainer}}{{#isListContainer}} ){{/isListContainer}}{{#isMapContainer}} ){{/isMapContainer}}{{/returnContainer}} \cr {{/returnTypeIsPrimitive}} {{/returnType}} #' diff --git a/modules/openapi-generator/src/main/resources/r/model.mustache b/modules/openapi-generator/src/main/resources/r/model.mustache index 48dd83a26fd9..04594e28a009 100644 --- a/modules/openapi-generator/src/main/resources/r/model.mustache +++ b/modules/openapi-generator/src/main/resources/r/model.mustache @@ -6,7 +6,7 @@ #' @description {{classname}} Class #' @format An \code{R6Class} generator object {{#vars}} -#' @field {{baseName}} {{title}} {{#isPrimitiveType}} {{#isContainer}}{{#isListContainer}}list({{#items}}{{dataType}}{{/items}}){{/isListContainer}}{{#isMapContainer}}named list({{#items}}{{dataType}}{{/items}}){{/isMapContainer}}{{/isContainer}} {{^isContainer}}{{dataType}}{{/isContainer}} {{/isPrimitiveType}} {{^isPrimitiveType}} \link{{=<% %>=}}{<%dataType%>}<%={{ }}=%>{{/isPrimitiveType}} {{^required}}[optional]{{/required}} +#' @field {{baseName}} {{title}} {{#isContainer}}{{#isListContainer}}list( {{/isListContainer}}{{#isMapContainer}}named list( {{/isMapContainer}}{{/isContainer}}{{^isPrimitiveType}}\link{{=<% %>=}}{<%/isPrimitiveType%><%={{ }}=%>{{#isContainer}}{{#items}}{{dataType}}{{/items}}{{/isContainer}}{{^isContainer}}{{dataType}}{{/isContainer}}{{=<% %>=}}<%^isPrimitiveType%>}<%={{ }}=%>{{/isPrimitiveType}}{{#isContainer}}{{#isListContainer}} ){{/isListContainer}}{{#isMapContainer}} ){{/isMapContainer}}{{/isContainer}} {{^required}}[optional]{{/required}} #' {{/vars}} #' From 456ac6a7658f6c26b056c702f0c6a7d132d11f27 Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Mon, 25 Nov 2019 09:25:29 -0500 Subject: [PATCH 06/26] run ./bin/r-petstore and update R pkg docs --- samples/client/petstore/R/R/category.R | 4 ++-- samples/client/petstore/R/R/model_api_response.R | 6 +++--- samples/client/petstore/R/R/order.R | 12 ++++++------ samples/client/petstore/R/R/pet.R | 12 ++++++------ samples/client/petstore/R/R/pet_api.R | 12 ++++++------ samples/client/petstore/R/R/store_api.R | 6 +++--- samples/client/petstore/R/R/tag.R | 4 ++-- samples/client/petstore/R/R/user.R | 16 ++++++++-------- samples/client/petstore/R/R/user_api.R | 10 +++++----- 9 files changed, 41 insertions(+), 41 deletions(-) diff --git a/samples/client/petstore/R/R/category.R b/samples/client/petstore/R/R/category.R index 05d5d77cce30..6ff2f1510cc9 100644 --- a/samples/client/petstore/R/R/category.R +++ b/samples/client/petstore/R/R/category.R @@ -10,9 +10,9 @@ #' @title Category #' @description Category Class #' @format An \code{R6Class} generator object -#' @field id integer [optional] +#' @field id integer [optional] #' -#' @field name character [optional] +#' @field name character [optional] #' #' #' @importFrom R6 R6Class diff --git a/samples/client/petstore/R/R/model_api_response.R b/samples/client/petstore/R/R/model_api_response.R index 747dcc550a50..ddf573164b77 100644 --- a/samples/client/petstore/R/R/model_api_response.R +++ b/samples/client/petstore/R/R/model_api_response.R @@ -10,11 +10,11 @@ #' @title ModelApiResponse #' @description ModelApiResponse Class #' @format An \code{R6Class} generator object -#' @field code integer [optional] +#' @field code integer [optional] #' -#' @field type character [optional] +#' @field type character [optional] #' -#' @field message character [optional] +#' @field message character [optional] #' #' #' @importFrom R6 R6Class diff --git a/samples/client/petstore/R/R/order.R b/samples/client/petstore/R/R/order.R index 4629dcfb7156..a5acac3bfffd 100644 --- a/samples/client/petstore/R/R/order.R +++ b/samples/client/petstore/R/R/order.R @@ -10,17 +10,17 @@ #' @title Order #' @description Order Class #' @format An \code{R6Class} generator object -#' @field id integer [optional] +#' @field id integer [optional] #' -#' @field petId integer [optional] +#' @field petId integer [optional] #' -#' @field quantity integer [optional] +#' @field quantity integer [optional] #' -#' @field shipDate character [optional] +#' @field shipDate character [optional] #' -#' @field status character [optional] +#' @field status character [optional] #' -#' @field complete character [optional] +#' @field complete character [optional] #' #' #' @importFrom R6 R6Class diff --git a/samples/client/petstore/R/R/pet.R b/samples/client/petstore/R/R/pet.R index 1b2f6161dd8c..307a5ed9704b 100644 --- a/samples/client/petstore/R/R/pet.R +++ b/samples/client/petstore/R/R/pet.R @@ -10,17 +10,17 @@ #' @title Pet #' @description Pet Class #' @format An \code{R6Class} generator object -#' @field id integer [optional] +#' @field id integer [optional] #' -#' @field category \link[petstore:Category]{ Category } [optional] +#' @field category \link{Category} [optional] #' -#' @field name character +#' @field name character #' -#' @field photoUrls list(character) +#' @field photoUrls list( character ) #' -#' @field tags \link[petstore:Tag]{ list(Tag) } [optional] +#' @field tags list( \link{Tag} ) [optional] #' -#' @field status character [optional] +#' @field status character [optional] #' #' #' @importFrom R6 R6Class diff --git a/samples/client/petstore/R/R/pet_api.R b/samples/client/petstore/R/R/pet_api.R index 7b038534f040..e0ad8275d826 100644 --- a/samples/client/petstore/R/R/pet_api.R +++ b/samples/client/petstore/R/R/pet_api.R @@ -18,7 +18,7 @@ #' #' #' \itemize{ -#' \item \emph{ @param } body \link[petstore:Pet]{ Pet } +#' \item \emph{ @param } body \link{Pet} #' #' #' \item status code : 405 | Invalid input @@ -52,7 +52,7 @@ #' #' \itemize{ #' \item \emph{ @param } status Enum < [available, pending, sold] > -#' \item \emph{ @returnType } \link[petstore:Pet]{ list(Pet) } \cr +#' \item \emph{ @returnType } list( \link{Pet} ) \cr #' #' #' \item status code : 200 | successful operation @@ -76,7 +76,7 @@ #' #' \itemize{ #' \item \emph{ @param } tags list( character ) -#' \item \emph{ @returnType } \link[petstore:Pet]{ list(Pet) } \cr +#' \item \emph{ @returnType } list( \link{Pet} ) \cr #' #' #' \item status code : 200 | successful operation @@ -100,7 +100,7 @@ #' #' \itemize{ #' \item \emph{ @param } pet.id integer -#' \item \emph{ @returnType } \link[petstore:Pet]{ Pet } \cr +#' \item \emph{ @returnType } \link{Pet} \cr #' #' #' \item status code : 200 | successful operation @@ -130,7 +130,7 @@ #' #' #' \itemize{ -#' \item \emph{ @param } body \link[petstore:Pet]{ Pet } +#' \item \emph{ @param } body \link{Pet} #' #' #' \item status code : 400 | Invalid ID supplied @@ -181,7 +181,7 @@ #' \item \emph{ @param } pet.id integer #' \item \emph{ @param } additional.metadata character #' \item \emph{ @param } file data.frame -#' \item \emph{ @returnType } \link[petstore:ApiResponse]{ ModelApiResponse } \cr +#' \item \emph{ @returnType } \link{ModelApiResponse} \cr #' #' #' \item status code : 200 | successful operation diff --git a/samples/client/petstore/R/R/store_api.R b/samples/client/petstore/R/R/store_api.R index d46e165c71bd..2205c3796d15 100644 --- a/samples/client/petstore/R/R/store_api.R +++ b/samples/client/petstore/R/R/store_api.R @@ -57,7 +57,7 @@ #' #' \itemize{ #' \item \emph{ @param } order.id integer -#' \item \emph{ @returnType } \link[petstore:Order]{ Order } \cr +#' \item \emph{ @returnType } \link{Order} \cr #' #' #' \item status code : 200 | successful operation @@ -87,8 +87,8 @@ #' #' #' \itemize{ -#' \item \emph{ @param } body \link[petstore:Order]{ Order } -#' \item \emph{ @returnType } \link[petstore:Order]{ Order } \cr +#' \item \emph{ @param } body \link{Order} +#' \item \emph{ @returnType } \link{Order} \cr #' #' #' \item status code : 200 | successful operation diff --git a/samples/client/petstore/R/R/tag.R b/samples/client/petstore/R/R/tag.R index 7e60cb50c822..5644807f5c60 100644 --- a/samples/client/petstore/R/R/tag.R +++ b/samples/client/petstore/R/R/tag.R @@ -10,9 +10,9 @@ #' @title Tag #' @description Tag Class #' @format An \code{R6Class} generator object -#' @field id integer [optional] +#' @field id integer [optional] #' -#' @field name character [optional] +#' @field name character [optional] #' #' #' @importFrom R6 R6Class diff --git a/samples/client/petstore/R/R/user.R b/samples/client/petstore/R/R/user.R index a3967c84c939..2afd3de04c6e 100644 --- a/samples/client/petstore/R/R/user.R +++ b/samples/client/petstore/R/R/user.R @@ -10,21 +10,21 @@ #' @title User #' @description User Class #' @format An \code{R6Class} generator object -#' @field id integer [optional] +#' @field id integer [optional] #' -#' @field username character [optional] +#' @field username character [optional] #' -#' @field firstName character [optional] +#' @field firstName character [optional] #' -#' @field lastName character [optional] +#' @field lastName character [optional] #' -#' @field email character [optional] +#' @field email character [optional] #' -#' @field password character [optional] +#' @field password character [optional] #' -#' @field phone character [optional] +#' @field phone character [optional] #' -#' @field userStatus integer [optional] +#' @field userStatus integer [optional] #' #' #' @importFrom R6 R6Class diff --git a/samples/client/petstore/R/R/user_api.R b/samples/client/petstore/R/R/user_api.R index 8eb742c60365..7fbcd73848b0 100644 --- a/samples/client/petstore/R/R/user_api.R +++ b/samples/client/petstore/R/R/user_api.R @@ -18,7 +18,7 @@ #' This can only be done by the logged in user. #' #' \itemize{ -#' \item \emph{ @param } body \link[petstore:User]{ User } +#' \item \emph{ @param } body \link{User} #' #' #' \item status code : 0 | successful operation @@ -34,7 +34,7 @@ #' #' #' \itemize{ -#' \item \emph{ @param } body list( \link[petstore:User]{ User } ) +#' \item \emph{ @param } body list( \link{User} ) #' #' #' \item status code : 0 | successful operation @@ -50,7 +50,7 @@ #' #' #' \itemize{ -#' \item \emph{ @param } body list( \link[petstore:User]{ User } ) +#' \item \emph{ @param } body list( \link{User} ) #' #' #' \item status code : 0 | successful operation @@ -90,7 +90,7 @@ #' #' \itemize{ #' \item \emph{ @param } username character -#' \item \emph{ @returnType } \link[petstore:User]{ User } \cr +#' \item \emph{ @returnType } \link{User} \cr #' #' #' \item status code : 200 | successful operation @@ -162,7 +162,7 @@ #' #' \itemize{ #' \item \emph{ @param } username character -#' \item \emph{ @param } body \link[petstore:User]{ User } +#' \item \emph{ @param } body \link{User} #' #' #' \item status code : 400 | Invalid user supplied From 0cb7abd902e177b970dbc4d75086bd5712d631f7 Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Tue, 26 Nov 2019 13:12:33 -0500 Subject: [PATCH 07/26] use loadNamespace instead of package:pkgName string --- modules/openapi-generator/src/main/resources/r/api.mustache | 2 +- modules/openapi-generator/src/main/resources/r/model.mustache | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/r/api.mustache b/modules/openapi-generator/src/main/resources/r/api.mustache index faae7a57b7fe..5fc18ec87e9e 100644 --- a/modules/openapi-generator/src/main/resources/r/api.mustache +++ b/modules/openapi-generator/src/main/resources/r/api.mustache @@ -276,7 +276,7 @@ {{/isPrimitiveType}} {{^isPrimitiveType}} deserializedRespObj <- tryCatch( - self$apiClient$deserialize(resp, "{{returnType}}", "package:{{packageName}}"), + self$apiClient$deserialize(resp, "{{returnType}}", loadNamespace("{{packageName}}")), error = function(e){ {{#useDefaultExceptionHandling}} stop("Failed to deserialize response") diff --git a/modules/openapi-generator/src/main/resources/r/model.mustache b/modules/openapi-generator/src/main/resources/r/model.mustache index 04594e28a009..bf04a1221447 100644 --- a/modules/openapi-generator/src/main/resources/r/model.mustache +++ b/modules/openapi-generator/src/main/resources/r/model.mustache @@ -145,7 +145,7 @@ {{#vars}} if (!is.null({{classname}}Object$`{{baseName}}`)) { {{#isContainer}} - self$`{{baseName}}` <- ApiClient$new()$deserializeObj({{classname}}Object$`{{baseName}}`, "{{dataType}}", "package:{{packageName}}") + self$`{{baseName}}` <- ApiClient$new()$deserializeObj({{classname}}Object$`{{baseName}}`, "{{dataType}}", loadNamespace("{{packageName}}")) {{/isContainer}} {{^isContainer}} {{#isPrimitiveType}} @@ -226,7 +226,7 @@ {{#vars}} {{! AAPI - added condition for handling container type of parameters, map and array}} {{#isContainer}} - self$`{{baseName}}` <- ApiClient$new()$deserializeObj({{classname}}Object$`{{baseName}}`, "{{dataType}}","package:{{packageName}}") + self$`{{baseName}}` <- ApiClient$new()$deserializeObj({{classname}}Object$`{{baseName}}`, "{{dataType}}", loadNamespace("{{packageName}}")) {{/isContainer}} {{^isContainer}} {{#isPrimitiveType}} From 5958c0185b694b4a950e53174684c3ba3f953ce7 Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Tue, 26 Nov 2019 13:23:36 -0500 Subject: [PATCH 08/26] update R package code --- samples/client/petstore/R/R/pet.R | 8 ++++---- samples/client/petstore/R/R/pet_api.R | 8 ++++---- samples/client/petstore/R/R/store_api.R | 6 +++--- samples/client/petstore/R/R/user_api.R | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/samples/client/petstore/R/R/pet.R b/samples/client/petstore/R/R/pet.R index 307a5ed9704b..760463d67baf 100644 --- a/samples/client/petstore/R/R/pet.R +++ b/samples/client/petstore/R/R/pet.R @@ -107,10 +107,10 @@ Pet <- R6::R6Class( self$`name` <- PetObject$`name` } if (!is.null(PetObject$`photoUrls`)) { - self$`photoUrls` <- ApiClient$new()$deserializeObj(PetObject$`photoUrls`, "array[character]", "package:petstore") + self$`photoUrls` <- ApiClient$new()$deserializeObj(PetObject$`photoUrls`, "array[character]", loadNamespace("petstore")) } if (!is.null(PetObject$`tags`)) { - self$`tags` <- ApiClient$new()$deserializeObj(PetObject$`tags`, "array[Tag]", "package:petstore") + self$`tags` <- ApiClient$new()$deserializeObj(PetObject$`tags`, "array[Tag]", loadNamespace("petstore")) } if (!is.null(PetObject$`status`)) { self$`status` <- PetObject$`status` @@ -169,8 +169,8 @@ Pet <- R6::R6Class( self$`id` <- PetObject$`id` self$`category` <- Category$new()$fromJSON(jsonlite::toJSON(PetObject$category, auto_unbox = TRUE, digits = NA)) self$`name` <- PetObject$`name` - self$`photoUrls` <- ApiClient$new()$deserializeObj(PetObject$`photoUrls`, "array[character]","package:petstore") - self$`tags` <- ApiClient$new()$deserializeObj(PetObject$`tags`, "array[Tag]","package:petstore") + self$`photoUrls` <- ApiClient$new()$deserializeObj(PetObject$`photoUrls`, "array[character]", loadNamespace("petstore")) + self$`tags` <- ApiClient$new()$deserializeObj(PetObject$`tags`, "array[Tag]", loadNamespace("petstore")) self$`status` <- PetObject$`status` self } diff --git a/samples/client/petstore/R/R/pet_api.R b/samples/client/petstore/R/R/pet_api.R index e0ad8275d826..f2e583bbcc54 100644 --- a/samples/client/petstore/R/R/pet_api.R +++ b/samples/client/petstore/R/R/pet_api.R @@ -469,7 +469,7 @@ PetApi <- R6::R6Class( if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { deserializedRespObj <- tryCatch( - self$apiClient$deserialize(resp, "array[Pet]", "package:petstore"), + self$apiClient$deserialize(resp, "array[Pet]", loadNamespace("petstore")), error = function(e){ stop("Failed to deserialize response") } @@ -521,7 +521,7 @@ PetApi <- R6::R6Class( if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { deserializedRespObj <- tryCatch( - self$apiClient$deserialize(resp, "array[Pet]", "package:petstore"), + self$apiClient$deserialize(resp, "array[Pet]", loadNamespace("petstore")), error = function(e){ stop("Failed to deserialize response") } @@ -577,7 +577,7 @@ PetApi <- R6::R6Class( if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { deserializedRespObj <- tryCatch( - self$apiClient$deserialize(resp, "Pet", "package:petstore"), + self$apiClient$deserialize(resp, "Pet", loadNamespace("petstore")), error = function(e){ stop("Failed to deserialize response") } @@ -739,7 +739,7 @@ PetApi <- R6::R6Class( if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { deserializedRespObj <- tryCatch( - self$apiClient$deserialize(resp, "ModelApiResponse", "package:petstore"), + self$apiClient$deserialize(resp, "ModelApiResponse", loadNamespace("petstore")), error = function(e){ stop("Failed to deserialize response") } diff --git a/samples/client/petstore/R/R/store_api.R b/samples/client/petstore/R/R/store_api.R index 2205c3796d15..8f45603288d6 100644 --- a/samples/client/petstore/R/R/store_api.R +++ b/samples/client/petstore/R/R/store_api.R @@ -254,7 +254,7 @@ StoreApi <- R6::R6Class( if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { deserializedRespObj <- tryCatch( - self$apiClient$deserialize(resp, "map(integer)", "package:petstore"), + self$apiClient$deserialize(resp, "map(integer)", loadNamespace("petstore")), error = function(e){ stop("Failed to deserialize response") } @@ -306,7 +306,7 @@ StoreApi <- R6::R6Class( if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { deserializedRespObj <- tryCatch( - self$apiClient$deserialize(resp, "Order", "package:petstore"), + self$apiClient$deserialize(resp, "Order", loadNamespace("petstore")), error = function(e){ stop("Failed to deserialize response") } @@ -360,7 +360,7 @@ StoreApi <- R6::R6Class( if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { deserializedRespObj <- tryCatch( - self$apiClient$deserialize(resp, "Order", "package:petstore"), + self$apiClient$deserialize(resp, "Order", loadNamespace("petstore")), error = function(e){ stop("Failed to deserialize response") } diff --git a/samples/client/petstore/R/R/user_api.R b/samples/client/petstore/R/R/user_api.R index 7fbcd73848b0..051b5ae89274 100644 --- a/samples/client/petstore/R/R/user_api.R +++ b/samples/client/petstore/R/R/user_api.R @@ -521,7 +521,7 @@ UserApi <- R6::R6Class( if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { deserializedRespObj <- tryCatch( - self$apiClient$deserialize(resp, "User", "package:petstore"), + self$apiClient$deserialize(resp, "User", loadNamespace("petstore")), error = function(e){ stop("Failed to deserialize response") } @@ -577,7 +577,7 @@ UserApi <- R6::R6Class( if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { deserializedRespObj <- tryCatch( - self$apiClient$deserialize(resp, "character", "package:petstore"), + self$apiClient$deserialize(resp, "character", loadNamespace("petstore")), error = function(e){ stop("Failed to deserialize response") } From 75280034f8d1189ac6e935c5c0a6dd9a850c1e2b Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Thu, 5 Dec 2019 18:17:09 -0500 Subject: [PATCH 09/26] wip: enum --- .../src/main/resources/r/model.mustache | 6 ++++ .../src/main/resources/r/modelEnum.mustache | 28 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 modules/openapi-generator/src/main/resources/r/modelEnum.mustache diff --git a/modules/openapi-generator/src/main/resources/r/model.mustache b/modules/openapi-generator/src/main/resources/r/model.mustache index bf04a1221447..70ab3d1b3a50 100644 --- a/modules/openapi-generator/src/main/resources/r/model.mustache +++ b/modules/openapi-generator/src/main/resources/r/model.mustache @@ -1,5 +1,6 @@ {{#models}} {{#model}} +{{> modelEnum}} {{>partial_header}} #' @docType class #' @title {{classname}} @@ -21,6 +22,11 @@ {{/vars}} initialize = function({{#requiredVars}}`{{baseName}}`{{#hasMore}}, {{/hasMore}}{{/requiredVars}}{{#optionalVars}}{{#-first}}{{#requiredVars.0}}, {{/requiredVars.0}}{{/-first}}`{{baseName}}`={{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}NULL{{/defaultValue}}{{^-last}}, {{/-last}}{{/optionalVars}}, ...){ local.optional.var <- list(...) + {{#isEnum}} + {{#allowableValues}} + # WIP: enumenv <- {{name}}_Enum() + {{/allowableValues}} + {{/isEnum}} {{#requiredVars}} if (!missing(`{{baseName}}`)) { {{^isContainer}} diff --git a/modules/openapi-generator/src/main/resources/r/modelEnum.mustache b/modules/openapi-generator/src/main/resources/r/modelEnum.mustache new file mode 100644 index 000000000000..139707df55f7 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/r/modelEnum.mustache @@ -0,0 +1,28 @@ + +{{#isEnum}} +#' @export +{{#allowableValues}} +{{name}}_Enum <- function() { + res <- gsub("\\[|\\]|,", "", + "{{values}}" + ) + htmlEncoded <- any(grepl("[&;]", res)) + if (htmlEncoded && !requireNamespace("XML", quietly = TRUE)) + stop("Install 'XML' package for converting html encoded characters") + if (htmlEncoded) { + html2txt <- function(str) { + XML::xpathApply(XML::htmlParse(str, asText=TRUE), + "//body//text()", + xmlValue)[[1L]] + } + res <- strsplit(xml2txt(res), "\n")[[1]] + } else + res <- unlist(strsplit(res, " ")) + res <- unlist(strsplit(res, " ")) + res <- setNames(res, res) + res <- as.environment(as.list(res)) + lockEnvironment(res, bindings = TRUE) + res +} +{{/allowableValues}} +{{/isEnum}} From 5d7e410bec78833388dc9f3b58d2c478b9da4ae9 Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Sat, 7 Dec 2019 16:15:41 -0500 Subject: [PATCH 10/26] update enum function --- .../src/main/resources/r/model.mustache | 2 +- .../src/main/resources/r/modelEnum.mustache | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/r/model.mustache b/modules/openapi-generator/src/main/resources/r/model.mustache index 70ab3d1b3a50..da9c4eb08de2 100644 --- a/modules/openapi-generator/src/main/resources/r/model.mustache +++ b/modules/openapi-generator/src/main/resources/r/model.mustache @@ -1,6 +1,6 @@ {{#models}} {{#model}} -{{> modelEnum}} +{{>modelEnum}} {{>partial_header}} #' @docType class #' @title {{classname}} diff --git a/modules/openapi-generator/src/main/resources/r/modelEnum.mustache b/modules/openapi-generator/src/main/resources/r/modelEnum.mustache index 139707df55f7..581600862a14 100644 --- a/modules/openapi-generator/src/main/resources/r/modelEnum.mustache +++ b/modules/openapi-generator/src/main/resources/r/modelEnum.mustache @@ -1,4 +1,3 @@ - {{#isEnum}} #' @export {{#allowableValues}} @@ -7,17 +6,18 @@ "{{values}}" ) htmlEncoded <- any(grepl("[&;]", res)) - if (htmlEncoded && !requireNamespace("XML", quietly = TRUE)) - stop("Install 'XML' package for converting html encoded characters") + if (htmlEncoded && !requireNamespace("xml2", quietly = TRUE)) + stop("Install 'xml2' package for converting html encoded characters") if (htmlEncoded) { html2txt <- function(str) { - XML::xpathApply(XML::htmlParse(str, asText=TRUE), - "//body//text()", - xmlValue)[[1L]] + xml2::xml_text( + xml2::read_html( + paste0("", str, "") + ) + ) } - res <- strsplit(xml2txt(res), "\n")[[1]] - } else - res <- unlist(strsplit(res, " ")) + res <- html2txt(res) + } res <- unlist(strsplit(res, " ")) res <- setNames(res, res) res <- as.environment(as.list(res)) From 231f03ff9adb86ca514d8027dba768d27f015594 Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Sat, 7 Dec 2019 16:16:33 -0500 Subject: [PATCH 11/26] use httr::content to unwrap response --- modules/openapi-generator/src/main/resources/r/api.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/r/api.mustache b/modules/openapi-generator/src/main/resources/r/api.mustache index 5fc18ec87e9e..43090f99aa62 100644 --- a/modules/openapi-generator/src/main/resources/r/api.mustache +++ b/modules/openapi-generator/src/main/resources/r/api.mustache @@ -163,7 +163,7 @@ apiResponse <- self${{{operationId}}}WithHttpInfo({{#allParams}}{{paramName}}, {{/allParams}}...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - apiResponse$content + httr::content(resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { From 8d78c2fdf89febbcfcc3ce9aa820e64634284b64 Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Fri, 3 Jan 2020 16:48:16 -0500 Subject: [PATCH 12/26] update enum table and functions --- .../src/main/resources/r/model.mustache | 35 ++++++++++++++++++- .../src/main/resources/r/modelEnum.mustache | 23 ++++++++---- 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/r/model.mustache b/modules/openapi-generator/src/main/resources/r/model.mustache index da9c4eb08de2..9b035649388a 100644 --- a/modules/openapi-generator/src/main/resources/r/model.mustache +++ b/modules/openapi-generator/src/main/resources/r/model.mustache @@ -20,11 +20,24 @@ {{#vars}} `{{{baseName}}}` = NULL, {{/vars}} + {{#isEnum}} + `{{name}}` = NULL, + {{/isEnum}} initialize = function({{#requiredVars}}`{{baseName}}`{{#hasMore}}, {{/hasMore}}{{/requiredVars}}{{#optionalVars}}{{#-first}}{{#requiredVars.0}}, {{/requiredVars.0}}{{/-first}}`{{baseName}}`={{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}NULL{{/defaultValue}}{{^-last}}, {{/-last}}{{/optionalVars}}, ...){ local.optional.var <- list(...) {{#isEnum}} {{#allowableValues}} - # WIP: enumenv <- {{name}}_Enum() + val <- unlist(local.optional.var) + enumlist <- {{name}}_Enum() + if (is.null(val)) + val <- names(enumlist)[[1L]] + else + stopifnot(length(val) == 1L) + + if (!val %in% names(enumlist)) + stop("Use one of the valid values: ", + paste0(names(enumlist), collapse = ", ")) + self$`{{name}}` <- val {{/allowableValues}} {{/isEnum}} {{#requiredVars}} @@ -111,6 +124,10 @@ {{/optionalVars}} }, toJSON = function() { + {{#isEnum}} + jsonlite::toJSON(self$`{{name}}`) + {{/isEnum}} + {{^isEnum}} {{classname}}Object <- list() {{#vars}} if (!is.null(self$`{{baseName}}`)) { @@ -145,8 +162,13 @@ {{/vars}} {{classname}}Object + {{/isEnum}} }, fromJSON = function({{classname}}Json) { + {{#isEnum}} + self$`{{name}}` <- jsonlite::fromJSON({{classname}}Json) + {{/isEnum}} + {{^isEnum}} {{classname}}Object <- jsonlite::fromJSON({{classname}}Json) {{#vars}} if (!is.null({{classname}}Object$`{{baseName}}`)) { @@ -165,8 +187,13 @@ {{/isContainer}} } {{/vars}} + {{/isEnum}} }, toJSONString = function() { + {{#isEnum}} + as.character(jsonlite::toJSON(self$`{{name}}`)) + {{/isEnum}} + {{^isEnum}} jsoncontent <- c( {{#vars}} if (!is.null(self$`{{baseName}}`)) { @@ -226,8 +253,13 @@ ) jsoncontent <- paste(jsoncontent, collapse = ",") paste('{', jsoncontent, '}', sep = "") + {{/isEnum}} }, fromJSONString = function({{classname}}Json) { + {{#isEnum}} + self$`{{name}}` <- jsonlite::fromJSON({{classname}}Json) + {{/isEnum}} + {{^isEnum}} {{classname}}Object <- jsonlite::fromJSON({{classname}}Json) {{#vars}} {{! AAPI - added condition for handling container type of parameters, map and array}} @@ -243,6 +275,7 @@ {{/isPrimitiveType}} {{/isContainer}} {{/vars}} + {{/isEnum}} self } ) diff --git a/modules/openapi-generator/src/main/resources/r/modelEnum.mustache b/modules/openapi-generator/src/main/resources/r/modelEnum.mustache index 581600862a14..f775e74349f4 100644 --- a/modules/openapi-generator/src/main/resources/r/modelEnum.mustache +++ b/modules/openapi-generator/src/main/resources/r/modelEnum.mustache @@ -2,7 +2,7 @@ #' @export {{#allowableValues}} {{name}}_Enum <- function() { - res <- gsub("\\[|\\]|,", "", + res <- gsub("\\[|\\]", "", "{{values}}" ) htmlEncoded <- any(grepl("[&;]", res)) @@ -18,11 +18,22 @@ } res <- html2txt(res) } - res <- unlist(strsplit(res, " ")) - res <- setNames(res, res) - res <- as.environment(as.list(res)) - lockEnvironment(res, bindings = TRUE) - res + + .names_table <- data.frame( + op = c("=", "!=", ">", "<", ">=", "<=", "in", "and", "or", "not"), + name = c("==", "!=", ">", "<", ">=", "<=", "%in%", "&", "|", "!"), + stringsAsFactors = FALSE + ) + + res <- unlist(strsplit(res, ", ")) + if (all(res %in% .names_table[["op"]])) + res <- setNames( + .names_table[na.omit(match(res, .names_table[["op"]])), "name"], + res + ) + else + res <- setNames(res, res) + as.list(res) } {{/allowableValues}} {{/isEnum}} From 9d178a17e4e2b2d8764f4c011663de5997562362 Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Mon, 6 Jan 2020 16:47:46 -0500 Subject: [PATCH 13/26] include simplifyVector and auto_unbox arguments --- .../src/main/resources/r/model.mustache | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/r/model.mustache b/modules/openapi-generator/src/main/resources/r/model.mustache index 9b035649388a..fe759ae8ed29 100644 --- a/modules/openapi-generator/src/main/resources/r/model.mustache +++ b/modules/openapi-generator/src/main/resources/r/model.mustache @@ -4,13 +4,15 @@ {{>partial_header}} #' @docType class #' @title {{classname}} +#' #' @description {{classname}} Class +#' #' @format An \code{R6Class} generator object +#' {{#vars}} #' @field {{baseName}} {{title}} {{#isContainer}}{{#isListContainer}}list( {{/isListContainer}}{{#isMapContainer}}named list( {{/isMapContainer}}{{/isContainer}}{{^isPrimitiveType}}\link{{=<% %>=}}{<%/isPrimitiveType%><%={{ }}=%>{{#isContainer}}{{#items}}{{dataType}}{{/items}}{{/isContainer}}{{^isContainer}}{{dataType}}{{/isContainer}}{{=<% %>=}}<%^isPrimitiveType%>}<%={{ }}=%>{{/isPrimitiveType}}{{#isContainer}}{{#isListContainer}} ){{/isListContainer}}{{#isMapContainer}} ){{/isMapContainer}}{{/isContainer}} {{^required}}[optional]{{/required}} #' {{/vars}} -#' #' @importFrom R6 R6Class #' @importFrom jsonlite fromJSON toJSON #' @export @@ -125,7 +127,7 @@ }, toJSON = function() { {{#isEnum}} - jsonlite::toJSON(self$`{{name}}`) + jsonlite::toJSON(self$`{{name}}`, auto_unbox = TRUE) {{/isEnum}} {{^isEnum}} {{classname}}Object <- list() @@ -166,10 +168,12 @@ }, fromJSON = function({{classname}}Json) { {{#isEnum}} - self$`{{name}}` <- jsonlite::fromJSON({{classname}}Json) + self$`{{name}}` <- jsonlite::fromJSON({{classname}}Json, + simplifyVector = FALSE) {{/isEnum}} {{^isEnum}} - {{classname}}Object <- jsonlite::fromJSON({{classname}}Json) + {{classname}}Object <- jsonlite::fromJSON({{classname}}Json, + simplifyVector = FALSE) {{#vars}} if (!is.null({{classname}}Object$`{{baseName}}`)) { {{#isContainer}} @@ -188,10 +192,12 @@ } {{/vars}} {{/isEnum}} + self }, toJSONString = function() { {{#isEnum}} - as.character(jsonlite::toJSON(self$`{{name}}`)) + as.character(jsonlite::toJSON(self$`{{name}}`, + auto_unbox = TRUE)) {{/isEnum}} {{^isEnum}} jsoncontent <- c( @@ -257,10 +263,12 @@ }, fromJSONString = function({{classname}}Json) { {{#isEnum}} - self$`{{name}}` <- jsonlite::fromJSON({{classname}}Json) + self$`{{name}}` <- jsonlite::fromJSON({{classname}}Json, + simplifyVector = FALSE) {{/isEnum}} {{^isEnum}} - {{classname}}Object <- jsonlite::fromJSON({{classname}}Json) + {{classname}}Object <- jsonlite::fromJSON({{classname}}Json, + simplifyVector = FALSE) {{#vars}} {{! AAPI - added condition for handling container type of parameters, map and array}} {{#isContainer}} From c5a445dfbdca75637b8e4fbf60a25b095a301954 Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Mon, 23 Mar 2020 19:36:19 -0400 Subject: [PATCH 14/26] remove mapping and return strings --- .../src/main/resources/r/model.mustache | 48 ++------------- .../src/main/resources/r/modelEnum.mustache | 60 ++++++++++++------- 2 files changed, 46 insertions(+), 62 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/r/model.mustache b/modules/openapi-generator/src/main/resources/r/model.mustache index fe759ae8ed29..5940b3be6b0f 100644 --- a/modules/openapi-generator/src/main/resources/r/model.mustache +++ b/modules/openapi-generator/src/main/resources/r/model.mustache @@ -1,6 +1,5 @@ {{#models}} {{#model}} -{{>modelEnum}} {{>partial_header}} #' @docType class #' @title {{classname}} @@ -15,6 +14,10 @@ {{/vars}} #' @importFrom R6 R6Class #' @importFrom jsonlite fromJSON toJSON +{{#isEnum}} +{{>modelEnum}} +{{/isEnum}} +{{^isEnum}} #' @export {{classname}} <- R6::R6Class( '{{classname}}', @@ -22,26 +25,8 @@ {{#vars}} `{{{baseName}}}` = NULL, {{/vars}} - {{#isEnum}} - `{{name}}` = NULL, - {{/isEnum}} initialize = function({{#requiredVars}}`{{baseName}}`{{#hasMore}}, {{/hasMore}}{{/requiredVars}}{{#optionalVars}}{{#-first}}{{#requiredVars.0}}, {{/requiredVars.0}}{{/-first}}`{{baseName}}`={{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}NULL{{/defaultValue}}{{^-last}}, {{/-last}}{{/optionalVars}}, ...){ local.optional.var <- list(...) - {{#isEnum}} - {{#allowableValues}} - val <- unlist(local.optional.var) - enumlist <- {{name}}_Enum() - if (is.null(val)) - val <- names(enumlist)[[1L]] - else - stopifnot(length(val) == 1L) - - if (!val %in% names(enumlist)) - stop("Use one of the valid values: ", - paste0(names(enumlist), collapse = ", ")) - self$`{{name}}` <- val - {{/allowableValues}} - {{/isEnum}} {{#requiredVars}} if (!missing(`{{baseName}}`)) { {{^isContainer}} @@ -126,10 +111,6 @@ {{/optionalVars}} }, toJSON = function() { - {{#isEnum}} - jsonlite::toJSON(self$`{{name}}`, auto_unbox = TRUE) - {{/isEnum}} - {{^isEnum}} {{classname}}Object <- list() {{#vars}} if (!is.null(self$`{{baseName}}`)) { @@ -164,14 +145,8 @@ {{/vars}} {{classname}}Object - {{/isEnum}} }, fromJSON = function({{classname}}Json) { - {{#isEnum}} - self$`{{name}}` <- jsonlite::fromJSON({{classname}}Json, - simplifyVector = FALSE) - {{/isEnum}} - {{^isEnum}} {{classname}}Object <- jsonlite::fromJSON({{classname}}Json, simplifyVector = FALSE) {{#vars}} @@ -191,15 +166,9 @@ {{/isContainer}} } {{/vars}} - {{/isEnum}} self }, toJSONString = function() { - {{#isEnum}} - as.character(jsonlite::toJSON(self$`{{name}}`, - auto_unbox = TRUE)) - {{/isEnum}} - {{^isEnum}} jsoncontent <- c( {{#vars}} if (!is.null(self$`{{baseName}}`)) { @@ -259,14 +228,8 @@ ) jsoncontent <- paste(jsoncontent, collapse = ",") paste('{', jsoncontent, '}', sep = "") - {{/isEnum}} }, fromJSONString = function({{classname}}Json) { - {{#isEnum}} - self$`{{name}}` <- jsonlite::fromJSON({{classname}}Json, - simplifyVector = FALSE) - {{/isEnum}} - {{^isEnum}} {{classname}}Object <- jsonlite::fromJSON({{classname}}Json, simplifyVector = FALSE) {{#vars}} @@ -283,10 +246,11 @@ {{/isPrimitiveType}} {{/isContainer}} {{/vars}} - {{/isEnum}} self } ) ) +{{/isEnum}} {{/model}} {{/models}} + diff --git a/modules/openapi-generator/src/main/resources/r/modelEnum.mustache b/modules/openapi-generator/src/main/resources/r/modelEnum.mustache index f775e74349f4..b68910688fa8 100644 --- a/modules/openapi-generator/src/main/resources/r/modelEnum.mustache +++ b/modules/openapi-generator/src/main/resources/r/modelEnum.mustache @@ -1,8 +1,7 @@ -{{#isEnum}} -#' @export +# add to utils.R {{#allowableValues}} -{{name}}_Enum <- function() { - res <- gsub("\\[|\\]", "", +.parse_{{name}} <- function(vals) { + res <- gsub("^\\[|\\]$", "", "{{values}}" ) htmlEncoded <- any(grepl("[&;]", res)) @@ -18,22 +17,43 @@ } res <- html2txt(res) } + unlist(strsplit(res, ", ")) +} - .names_table <- data.frame( - op = c("=", "!=", ">", "<", ">=", "<=", "in", "and", "or", "not"), - name = c("==", "!=", ">", "<", ">=", "<=", "%in%", "&", "|", "!"), - stringsAsFactors = FALSE - ) +#' @export +{{classname}} <- R6::R6Class( + "{{classname}}", + public = list( + `{{name}}` = NULL, + initialize = function({{#requiredVars}}`{{baseName}}`{{#hasMore}}, {{/hasMore}}{{/requiredVars}}{{#optionalVars}}{{#-first}}{{#requiredVars.0}}, {{/requiredVars.0}}{{/-first}}`{{baseName}}`={{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}NULL{{/defaultValue}}{{^-last}}, {{/-last}}{{/optionalVars}}, ...) { + local.optional.var <- list(...) + val <- unlist(local.optional.var) + enumvec <- .parse_{{name}}() - res <- unlist(strsplit(res, ", ")) - if (all(res %in% .names_table[["op"]])) - res <- setNames( - .names_table[na.omit(match(res, .names_table[["op"]])), "name"], - res - ) - else - res <- setNames(res, res) - as.list(res) -} + stopifnot(length(val) == 1L) + + if (!val %in% enumvec) + stop("Use one of the valid values: ", + paste0(enumvec, collapse = ", ")) + self$`{{name}}` <- val + }, + toJSON = function() { + jsonlite::toJSON(self$`{{name}}`, auto_unbox = TRUE) + }, + fromJSON = function() { + self$`{{name}}` <- jsonlite::fromJSON({{classname}}Json, + simplifyVector = FALSE) + self + }, + toJSONString = function() { + as.character(jsonlite::toJSON(self$`{{name}}`, + auto_unbox = TRUE)) + }, + fromJSONString = function() { + self$`{{name}}` <- jsonlite::fromJSON({{classname}}Json, + simplifyVector = FALSE) + self + } + ) +) {{/allowableValues}} -{{/isEnum}} From c419f8cd6fab3a2af992ad772bfe78a5d49dda79 Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Wed, 25 Mar 2020 00:12:25 -0400 Subject: [PATCH 15/26] use triple stash values and update enum class methods --- .../src/main/resources/r/modelEnum.mustache | 35 +++++++------------ 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/r/modelEnum.mustache b/modules/openapi-generator/src/main/resources/r/modelEnum.mustache index b68910688fa8..39f96c80de56 100644 --- a/modules/openapi-generator/src/main/resources/r/modelEnum.mustache +++ b/modules/openapi-generator/src/main/resources/r/modelEnum.mustache @@ -2,21 +2,8 @@ {{#allowableValues}} .parse_{{name}} <- function(vals) { res <- gsub("^\\[|\\]$", "", - "{{values}}" + "{{{values}}}" ) - htmlEncoded <- any(grepl("[&;]", res)) - if (htmlEncoded && !requireNamespace("xml2", quietly = TRUE)) - stop("Install 'xml2' package for converting html encoded characters") - if (htmlEncoded) { - html2txt <- function(str) { - xml2::xml_text( - xml2::read_html( - paste0("", str, "") - ) - ) - } - res <- html2txt(res) - } unlist(strsplit(res, ", ")) } @@ -24,8 +11,7 @@ {{classname}} <- R6::R6Class( "{{classname}}", public = list( - `{{name}}` = NULL, - initialize = function({{#requiredVars}}`{{baseName}}`{{#hasMore}}, {{/hasMore}}{{/requiredVars}}{{#optionalVars}}{{#-first}}{{#requiredVars.0}}, {{/requiredVars.0}}{{/-first}}`{{baseName}}`={{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}NULL{{/defaultValue}}{{^-last}}, {{/-last}}{{/optionalVars}}, ...) { + initialize = function(...) { local.optional.var <- list(...) val <- unlist(local.optional.var) enumvec <- .parse_{{name}}() @@ -35,25 +21,28 @@ if (!val %in% enumvec) stop("Use one of the valid values: ", paste0(enumvec, collapse = ", ")) - self$`{{name}}` <- val + private$value <- val }, toJSON = function() { - jsonlite::toJSON(self$`{{name}}`, auto_unbox = TRUE) + jsonlite::toJSON(private$value, auto_unbox = TRUE) }, - fromJSON = function() { - self$`{{name}}` <- jsonlite::fromJSON({{classname}}Json, + fromJSON = function({{classname}}Json) { + private$value <- jsonlite::fromJSON({{classname}}Json, simplifyVector = FALSE) self }, toJSONString = function() { - as.character(jsonlite::toJSON(self$`{{name}}`, + as.character(jsonlite::toJSON(private$value, auto_unbox = TRUE)) }, - fromJSONString = function() { - self$`{{name}}` <- jsonlite::fromJSON({{classname}}Json, + fromJSONString = function({{classname}}Json) { + private$value <- jsonlite::fromJSON({{classname}}Json, simplifyVector = FALSE) self } + ), + private = list( + value = NULL ) ) {{/allowableValues}} From 595b7ba1ac96cf0f625e722f7d88e98cb2cd2afb Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Wed, 25 Mar 2020 20:47:07 -0400 Subject: [PATCH 16/26] remove extra comma --- modules/openapi-generator/src/main/resources/r/model.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/r/model.mustache b/modules/openapi-generator/src/main/resources/r/model.mustache index 5940b3be6b0f..6dada6b5efae 100644 --- a/modules/openapi-generator/src/main/resources/r/model.mustache +++ b/modules/openapi-generator/src/main/resources/r/model.mustache @@ -25,7 +25,7 @@ {{#vars}} `{{{baseName}}}` = NULL, {{/vars}} - initialize = function({{#requiredVars}}`{{baseName}}`{{#hasMore}}, {{/hasMore}}{{/requiredVars}}{{#optionalVars}}{{#-first}}{{#requiredVars.0}}, {{/requiredVars.0}}{{/-first}}`{{baseName}}`={{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}NULL{{/defaultValue}}{{^-last}}, {{/-last}}{{/optionalVars}}, ...){ + initialize = function({{#requiredVars}}`{{baseName}}`, {{/requiredVars}}{{#optionalVars}}`{{baseName}}`={{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}NULL{{/defaultValue}}, {{/optionalVars}}...){ local.optional.var <- list(...) {{#requiredVars}} if (!missing(`{{baseName}}`)) { From 90c0dd5249a9dd41e73ca8be288c376a7fbc7279 Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Wed, 25 Mar 2020 20:47:42 -0400 Subject: [PATCH 17/26] minor: formatting --- modules/openapi-generator/src/main/resources/r/model.mustache | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/r/model.mustache b/modules/openapi-generator/src/main/resources/r/model.mustache index 6dada6b5efae..1466edb6b0b3 100644 --- a/modules/openapi-generator/src/main/resources/r/model.mustache +++ b/modules/openapi-generator/src/main/resources/r/model.mustache @@ -25,7 +25,9 @@ {{#vars}} `{{{baseName}}}` = NULL, {{/vars}} - initialize = function({{#requiredVars}}`{{baseName}}`, {{/requiredVars}}{{#optionalVars}}`{{baseName}}`={{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}NULL{{/defaultValue}}, {{/optionalVars}}...){ + initialize = function( + {{#requiredVars}}`{{baseName}}`, {{/requiredVars}}{{#optionalVars}}`{{baseName}}`={{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}NULL{{/defaultValue}}, {{/optionalVars}}... + ) { local.optional.var <- list(...) {{#requiredVars}} if (!missing(`{{baseName}}`)) { From 7eec6f6086dbf68b5ba63e16913c69f54838b443 Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Fri, 27 Mar 2020 11:16:08 -0400 Subject: [PATCH 18/26] update and run ./bin/r-petstore.sh --- samples/client/petstore/R/R/category.R | 16 ++++++++++++---- samples/client/petstore/R/R/model_api_response.R | 16 ++++++++++++---- samples/client/petstore/R/R/order.R | 16 ++++++++++++---- samples/client/petstore/R/R/pet.R | 16 ++++++++++++---- samples/client/petstore/R/R/pet_api.R | 16 ++++++++-------- samples/client/petstore/R/R/store_api.R | 8 ++++---- samples/client/petstore/R/R/tag.R | 16 ++++++++++++---- samples/client/petstore/R/R/user.R | 16 ++++++++++++---- samples/client/petstore/R/R/user_api.R | 16 ++++++++-------- 9 files changed, 92 insertions(+), 44 deletions(-) diff --git a/samples/client/petstore/R/R/category.R b/samples/client/petstore/R/R/category.R index 6ff2f1510cc9..361917d6aab5 100644 --- a/samples/client/petstore/R/R/category.R +++ b/samples/client/petstore/R/R/category.R @@ -8,13 +8,15 @@ #' @docType class #' @title Category +#' #' @description Category Class +#' #' @format An \code{R6Class} generator object +#' #' @field id integer [optional] #' #' @field name character [optional] #' -#' #' @importFrom R6 R6Class #' @importFrom jsonlite fromJSON toJSON #' @export @@ -23,7 +25,9 @@ Category <- R6::R6Class( public = list( `id` = NULL, `name` = NULL, - initialize = function(`id`=NULL, `name`=NULL, ...){ + initialize = function( + `id`=NULL, `name`=NULL, ... + ) { local.optional.var <- list(...) if (!is.null(`id`)) { stopifnot(is.numeric(`id`), length(`id`) == 1) @@ -48,13 +52,15 @@ Category <- R6::R6Class( CategoryObject }, fromJSON = function(CategoryJson) { - CategoryObject <- jsonlite::fromJSON(CategoryJson) + CategoryObject <- jsonlite::fromJSON(CategoryJson, + simplifyVector = FALSE) if (!is.null(CategoryObject$`id`)) { self$`id` <- CategoryObject$`id` } if (!is.null(CategoryObject$`name`)) { self$`name` <- CategoryObject$`name` } + self }, toJSONString = function() { jsoncontent <- c( @@ -77,10 +83,12 @@ Category <- R6::R6Class( paste('{', jsoncontent, '}', sep = "") }, fromJSONString = function(CategoryJson) { - CategoryObject <- jsonlite::fromJSON(CategoryJson) + CategoryObject <- jsonlite::fromJSON(CategoryJson, + simplifyVector = FALSE) self$`id` <- CategoryObject$`id` self$`name` <- CategoryObject$`name` self } ) ) + diff --git a/samples/client/petstore/R/R/model_api_response.R b/samples/client/petstore/R/R/model_api_response.R index ddf573164b77..f2efc696d6ff 100644 --- a/samples/client/petstore/R/R/model_api_response.R +++ b/samples/client/petstore/R/R/model_api_response.R @@ -8,15 +8,17 @@ #' @docType class #' @title ModelApiResponse +#' #' @description ModelApiResponse Class +#' #' @format An \code{R6Class} generator object +#' #' @field code integer [optional] #' #' @field type character [optional] #' #' @field message character [optional] #' -#' #' @importFrom R6 R6Class #' @importFrom jsonlite fromJSON toJSON #' @export @@ -26,7 +28,9 @@ ModelApiResponse <- R6::R6Class( `code` = NULL, `type` = NULL, `message` = NULL, - initialize = function(`code`=NULL, `type`=NULL, `message`=NULL, ...){ + initialize = function( + `code`=NULL, `type`=NULL, `message`=NULL, ... + ) { local.optional.var <- list(...) if (!is.null(`code`)) { stopifnot(is.numeric(`code`), length(`code`) == 1) @@ -59,7 +63,8 @@ ModelApiResponse <- R6::R6Class( ModelApiResponseObject }, fromJSON = function(ModelApiResponseJson) { - ModelApiResponseObject <- jsonlite::fromJSON(ModelApiResponseJson) + ModelApiResponseObject <- jsonlite::fromJSON(ModelApiResponseJson, + simplifyVector = FALSE) if (!is.null(ModelApiResponseObject$`code`)) { self$`code` <- ModelApiResponseObject$`code` } @@ -69,6 +74,7 @@ ModelApiResponse <- R6::R6Class( if (!is.null(ModelApiResponseObject$`message`)) { self$`message` <- ModelApiResponseObject$`message` } + self }, toJSONString = function() { jsoncontent <- c( @@ -98,7 +104,8 @@ ModelApiResponse <- R6::R6Class( paste('{', jsoncontent, '}', sep = "") }, fromJSONString = function(ModelApiResponseJson) { - ModelApiResponseObject <- jsonlite::fromJSON(ModelApiResponseJson) + ModelApiResponseObject <- jsonlite::fromJSON(ModelApiResponseJson, + simplifyVector = FALSE) self$`code` <- ModelApiResponseObject$`code` self$`type` <- ModelApiResponseObject$`type` self$`message` <- ModelApiResponseObject$`message` @@ -106,3 +113,4 @@ ModelApiResponse <- R6::R6Class( } ) ) + diff --git a/samples/client/petstore/R/R/order.R b/samples/client/petstore/R/R/order.R index a5acac3bfffd..0b17d711f9d0 100644 --- a/samples/client/petstore/R/R/order.R +++ b/samples/client/petstore/R/R/order.R @@ -8,8 +8,11 @@ #' @docType class #' @title Order +#' #' @description Order Class +#' #' @format An \code{R6Class} generator object +#' #' @field id integer [optional] #' #' @field petId integer [optional] @@ -22,7 +25,6 @@ #' #' @field complete character [optional] #' -#' #' @importFrom R6 R6Class #' @importFrom jsonlite fromJSON toJSON #' @export @@ -35,7 +37,9 @@ Order <- R6::R6Class( `shipDate` = NULL, `status` = NULL, `complete` = NULL, - initialize = function(`id`=NULL, `petId`=NULL, `quantity`=NULL, `shipDate`=NULL, `status`=NULL, `complete`=FALSE, ...){ + initialize = function( + `id`=NULL, `petId`=NULL, `quantity`=NULL, `shipDate`=NULL, `status`=NULL, `complete`=FALSE, ... + ) { local.optional.var <- list(...) if (!is.null(`id`)) { stopifnot(is.numeric(`id`), length(`id`) == 1) @@ -91,7 +95,8 @@ Order <- R6::R6Class( OrderObject }, fromJSON = function(OrderJson) { - OrderObject <- jsonlite::fromJSON(OrderJson) + OrderObject <- jsonlite::fromJSON(OrderJson, + simplifyVector = FALSE) if (!is.null(OrderObject$`id`)) { self$`id` <- OrderObject$`id` } @@ -110,6 +115,7 @@ Order <- R6::R6Class( if (!is.null(OrderObject$`complete`)) { self$`complete` <- OrderObject$`complete` } + self }, toJSONString = function() { jsoncontent <- c( @@ -160,7 +166,8 @@ Order <- R6::R6Class( paste('{', jsoncontent, '}', sep = "") }, fromJSONString = function(OrderJson) { - OrderObject <- jsonlite::fromJSON(OrderJson) + OrderObject <- jsonlite::fromJSON(OrderJson, + simplifyVector = FALSE) self$`id` <- OrderObject$`id` self$`petId` <- OrderObject$`petId` self$`quantity` <- OrderObject$`quantity` @@ -171,3 +178,4 @@ Order <- R6::R6Class( } ) ) + diff --git a/samples/client/petstore/R/R/pet.R b/samples/client/petstore/R/R/pet.R index 760463d67baf..90bcdf1762d0 100644 --- a/samples/client/petstore/R/R/pet.R +++ b/samples/client/petstore/R/R/pet.R @@ -8,8 +8,11 @@ #' @docType class #' @title Pet +#' #' @description Pet Class +#' #' @format An \code{R6Class} generator object +#' #' @field id integer [optional] #' #' @field category \link{Category} [optional] @@ -22,7 +25,6 @@ #' #' @field status character [optional] #' -#' #' @importFrom R6 R6Class #' @importFrom jsonlite fromJSON toJSON #' @export @@ -35,7 +37,9 @@ Pet <- R6::R6Class( `photoUrls` = NULL, `tags` = NULL, `status` = NULL, - initialize = function(`name`, `photoUrls`, `id`=NULL, `category`=NULL, `tags`=NULL, `status`=NULL, ...){ + initialize = function( + `name`, `photoUrls`, `id`=NULL, `category`=NULL, `tags`=NULL, `status`=NULL, ... + ) { local.optional.var <- list(...) if (!missing(`name`)) { stopifnot(is.character(`name`), length(`name`) == 1) @@ -94,7 +98,8 @@ Pet <- R6::R6Class( PetObject }, fromJSON = function(PetJson) { - PetObject <- jsonlite::fromJSON(PetJson) + PetObject <- jsonlite::fromJSON(PetJson, + simplifyVector = FALSE) if (!is.null(PetObject$`id`)) { self$`id` <- PetObject$`id` } @@ -115,6 +120,7 @@ Pet <- R6::R6Class( if (!is.null(PetObject$`status`)) { self$`status` <- PetObject$`status` } + self }, toJSONString = function() { jsoncontent <- c( @@ -165,7 +171,8 @@ Pet <- R6::R6Class( paste('{', jsoncontent, '}', sep = "") }, fromJSONString = function(PetJson) { - PetObject <- jsonlite::fromJSON(PetJson) + PetObject <- jsonlite::fromJSON(PetJson, + simplifyVector = FALSE) self$`id` <- PetObject$`id` self$`category` <- Category$new()$fromJSON(jsonlite::toJSON(PetObject$category, auto_unbox = TRUE, digits = NA)) self$`name` <- PetObject$`name` @@ -176,3 +183,4 @@ Pet <- R6::R6Class( } ) ) + diff --git a/samples/client/petstore/R/R/pet_api.R b/samples/client/petstore/R/R/pet_api.R index 9fad358f4f9e..133ce8cb27a9 100644 --- a/samples/client/petstore/R/R/pet_api.R +++ b/samples/client/petstore/R/R/pet_api.R @@ -335,7 +335,7 @@ PetApi <- R6::R6Class( apiResponse <- self$AddPetWithHttpInfo(body, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - apiResponse$content + httr::content(resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -385,7 +385,7 @@ PetApi <- R6::R6Class( apiResponse <- self$DeletePetWithHttpInfo(pet.id, api.key, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - apiResponse$content + httr::content(resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -435,7 +435,7 @@ PetApi <- R6::R6Class( apiResponse <- self$FindPetsByStatusWithHttpInfo(status, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - apiResponse$content + httr::content(resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -487,7 +487,7 @@ PetApi <- R6::R6Class( apiResponse <- self$FindPetsByTagsWithHttpInfo(tags, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - apiResponse$content + httr::content(resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -539,7 +539,7 @@ PetApi <- R6::R6Class( apiResponse <- self$GetPetByIdWithHttpInfo(pet.id, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - apiResponse$content + httr::content(resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -595,7 +595,7 @@ PetApi <- R6::R6Class( apiResponse <- self$UpdatePetWithHttpInfo(body, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - apiResponse$content + httr::content(resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -645,7 +645,7 @@ PetApi <- R6::R6Class( apiResponse <- self$UpdatePetWithFormWithHttpInfo(pet.id, name, status, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - apiResponse$content + httr::content(resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -698,7 +698,7 @@ PetApi <- R6::R6Class( apiResponse <- self$UploadFileWithHttpInfo(pet.id, additional.metadata, file, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - apiResponse$content + httr::content(resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { diff --git a/samples/client/petstore/R/R/store_api.R b/samples/client/petstore/R/R/store_api.R index ba525799db51..409a8080bf6f 100644 --- a/samples/client/petstore/R/R/store_api.R +++ b/samples/client/petstore/R/R/store_api.R @@ -178,7 +178,7 @@ StoreApi <- R6::R6Class( apiResponse <- self$DeleteOrderWithHttpInfo(order.id, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - apiResponse$content + httr::content(resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -224,7 +224,7 @@ StoreApi <- R6::R6Class( apiResponse <- self$GetInventoryWithHttpInfo(...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - apiResponse$content + httr::content(resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -272,7 +272,7 @@ StoreApi <- R6::R6Class( apiResponse <- self$GetOrderByIdWithHttpInfo(order.id, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - apiResponse$content + httr::content(resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -324,7 +324,7 @@ StoreApi <- R6::R6Class( apiResponse <- self$PlaceOrderWithHttpInfo(body, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - apiResponse$content + httr::content(resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { diff --git a/samples/client/petstore/R/R/tag.R b/samples/client/petstore/R/R/tag.R index 5644807f5c60..3f28c01fa823 100644 --- a/samples/client/petstore/R/R/tag.R +++ b/samples/client/petstore/R/R/tag.R @@ -8,13 +8,15 @@ #' @docType class #' @title Tag +#' #' @description Tag Class +#' #' @format An \code{R6Class} generator object +#' #' @field id integer [optional] #' #' @field name character [optional] #' -#' #' @importFrom R6 R6Class #' @importFrom jsonlite fromJSON toJSON #' @export @@ -23,7 +25,9 @@ Tag <- R6::R6Class( public = list( `id` = NULL, `name` = NULL, - initialize = function(`id`=NULL, `name`=NULL, ...){ + initialize = function( + `id`=NULL, `name`=NULL, ... + ) { local.optional.var <- list(...) if (!is.null(`id`)) { stopifnot(is.numeric(`id`), length(`id`) == 1) @@ -48,13 +52,15 @@ Tag <- R6::R6Class( TagObject }, fromJSON = function(TagJson) { - TagObject <- jsonlite::fromJSON(TagJson) + TagObject <- jsonlite::fromJSON(TagJson, + simplifyVector = FALSE) if (!is.null(TagObject$`id`)) { self$`id` <- TagObject$`id` } if (!is.null(TagObject$`name`)) { self$`name` <- TagObject$`name` } + self }, toJSONString = function() { jsoncontent <- c( @@ -77,10 +83,12 @@ Tag <- R6::R6Class( paste('{', jsoncontent, '}', sep = "") }, fromJSONString = function(TagJson) { - TagObject <- jsonlite::fromJSON(TagJson) + TagObject <- jsonlite::fromJSON(TagJson, + simplifyVector = FALSE) self$`id` <- TagObject$`id` self$`name` <- TagObject$`name` self } ) ) + diff --git a/samples/client/petstore/R/R/user.R b/samples/client/petstore/R/R/user.R index 2afd3de04c6e..b5ac17a386fe 100644 --- a/samples/client/petstore/R/R/user.R +++ b/samples/client/petstore/R/R/user.R @@ -8,8 +8,11 @@ #' @docType class #' @title User +#' #' @description User Class +#' #' @format An \code{R6Class} generator object +#' #' @field id integer [optional] #' #' @field username character [optional] @@ -26,7 +29,6 @@ #' #' @field userStatus integer [optional] #' -#' #' @importFrom R6 R6Class #' @importFrom jsonlite fromJSON toJSON #' @export @@ -41,7 +43,9 @@ User <- R6::R6Class( `password` = NULL, `phone` = NULL, `userStatus` = NULL, - initialize = function(`id`=NULL, `username`=NULL, `firstName`=NULL, `lastName`=NULL, `email`=NULL, `password`=NULL, `phone`=NULL, `userStatus`=NULL, ...){ + initialize = function( + `id`=NULL, `username`=NULL, `firstName`=NULL, `lastName`=NULL, `email`=NULL, `password`=NULL, `phone`=NULL, `userStatus`=NULL, ... + ) { local.optional.var <- list(...) if (!is.null(`id`)) { stopifnot(is.numeric(`id`), length(`id`) == 1) @@ -114,7 +118,8 @@ User <- R6::R6Class( UserObject }, fromJSON = function(UserJson) { - UserObject <- jsonlite::fromJSON(UserJson) + UserObject <- jsonlite::fromJSON(UserJson, + simplifyVector = FALSE) if (!is.null(UserObject$`id`)) { self$`id` <- UserObject$`id` } @@ -139,6 +144,7 @@ User <- R6::R6Class( if (!is.null(UserObject$`userStatus`)) { self$`userStatus` <- UserObject$`userStatus` } + self }, toJSONString = function() { jsoncontent <- c( @@ -203,7 +209,8 @@ User <- R6::R6Class( paste('{', jsoncontent, '}', sep = "") }, fromJSONString = function(UserJson) { - UserObject <- jsonlite::fromJSON(UserJson) + UserObject <- jsonlite::fromJSON(UserJson, + simplifyVector = FALSE) self$`id` <- UserObject$`id` self$`username` <- UserObject$`username` self$`firstName` <- UserObject$`firstName` @@ -216,3 +223,4 @@ User <- R6::R6Class( } ) ) + diff --git a/samples/client/petstore/R/R/user_api.R b/samples/client/petstore/R/R/user_api.R index 4c4afbeb72bf..b8e03881440b 100644 --- a/samples/client/petstore/R/R/user_api.R +++ b/samples/client/petstore/R/R/user_api.R @@ -295,7 +295,7 @@ UserApi <- R6::R6Class( apiResponse <- self$CreateUserWithHttpInfo(body, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - apiResponse$content + httr::content(resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -343,7 +343,7 @@ UserApi <- R6::R6Class( apiResponse <- self$CreateUsersWithArrayInputWithHttpInfo(body, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - apiResponse$content + httr::content(resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -392,7 +392,7 @@ UserApi <- R6::R6Class( apiResponse <- self$CreateUsersWithListInputWithHttpInfo(body, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - apiResponse$content + httr::content(resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -441,7 +441,7 @@ UserApi <- R6::R6Class( apiResponse <- self$DeleteUserWithHttpInfo(username, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - apiResponse$content + httr::content(resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -487,7 +487,7 @@ UserApi <- R6::R6Class( apiResponse <- self$GetUserByNameWithHttpInfo(username, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - apiResponse$content + httr::content(resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -539,7 +539,7 @@ UserApi <- R6::R6Class( apiResponse <- self$LoginUserWithHttpInfo(username, password, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - apiResponse$content + httr::content(resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -595,7 +595,7 @@ UserApi <- R6::R6Class( apiResponse <- self$LogoutUserWithHttpInfo(...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - apiResponse$content + httr::content(resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -633,7 +633,7 @@ UserApi <- R6::R6Class( apiResponse <- self$UpdateUserWithHttpInfo(username, body, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - apiResponse$content + httr::content(resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { From 0580ea7e60fd0dad19333cf9b18fff6b26fc1bd4 Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Tue, 12 May 2020 09:29:18 -0400 Subject: [PATCH 19/26] move helper for template - export tag does not coincide with original model function - move helper down so it does --- .../src/main/resources/r/modelEnum.mustache | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/r/modelEnum.mustache b/modules/openapi-generator/src/main/resources/r/modelEnum.mustache index 39f96c80de56..c648c0365fcc 100644 --- a/modules/openapi-generator/src/main/resources/r/modelEnum.mustache +++ b/modules/openapi-generator/src/main/resources/r/modelEnum.mustache @@ -1,13 +1,5 @@ -# add to utils.R -{{#allowableValues}} -.parse_{{name}} <- function(vals) { - res <- gsub("^\\[|\\]$", "", - "{{{values}}}" - ) - unlist(strsplit(res, ", ")) -} - #' @export +{{#allowableValues}} {{classname}} <- R6::R6Class( "{{classname}}", public = list( @@ -45,4 +37,12 @@ value = NULL ) ) + +# add to utils.R +.parse_{{name}} <- function(vals) { + res <- gsub("^\\[|\\]$", "", + "{{{values}}}" + ) + unlist(strsplit(res, ", ")) +} {{/allowableValues}} From b6314c8927a8411561577c0dfd100018947de42e Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Tue, 12 May 2020 18:11:26 -0400 Subject: [PATCH 20/26] update tests based on generator --- .../petstore/R/tests/testthat/test_order.R | 12 ++-- .../petstore/R/tests/testthat/test_pet.R | 8 +-- .../petstore/R/tests/testthat/test_pet_api.R | 46 ++++++------- .../petstore/R/tests/testthat/test_petstore.R | 68 ------------------- .../R/tests/testthat/test_store_api.R | 16 ++--- .../petstore/R/tests/testthat/test_user.R | 18 ++--- .../petstore/R/tests/testthat/test_user_api.R | 34 +++++----- 7 files changed, 67 insertions(+), 135 deletions(-) delete mode 100644 samples/client/petstore/R/tests/testthat/test_petstore.R diff --git a/samples/client/petstore/R/tests/testthat/test_order.R b/samples/client/petstore/R/tests/testthat/test_order.R index 5fb144f9372b..33b87520254d 100644 --- a/samples/client/petstore/R/tests/testthat/test_order.R +++ b/samples/client/petstore/R/tests/testthat/test_order.R @@ -12,11 +12,11 @@ test_that("id", { #expect_equal(model.instance$`id`, "EXPECTED_RESULT") }) -test_that("pet_id", { - # tests for the property `pet_id` (integer) +test_that("petId", { + # tests for the property `petId` (integer) # uncomment below to test the property - #expect_equal(model.instance$`pet_id`, "EXPECTED_RESULT") + #expect_equal(model.instance$`petId`, "EXPECTED_RESULT") }) test_that("quantity", { @@ -26,11 +26,11 @@ test_that("quantity", { #expect_equal(model.instance$`quantity`, "EXPECTED_RESULT") }) -test_that("ship_date", { - # tests for the property `ship_date` (character) +test_that("shipDate", { + # tests for the property `shipDate` (character) # uncomment below to test the property - #expect_equal(model.instance$`ship_date`, "EXPECTED_RESULT") + #expect_equal(model.instance$`shipDate`, "EXPECTED_RESULT") }) test_that("status", { diff --git a/samples/client/petstore/R/tests/testthat/test_pet.R b/samples/client/petstore/R/tests/testthat/test_pet.R index 8d3ce54a55d1..ac3e4f31dd10 100644 --- a/samples/client/petstore/R/tests/testthat/test_pet.R +++ b/samples/client/petstore/R/tests/testthat/test_pet.R @@ -26,15 +26,15 @@ test_that("name", { #expect_equal(model.instance$`name`, "EXPECTED_RESULT") }) -test_that("photo_urls", { - # tests for the property `photo_urls` (character) +test_that("photoUrls", { + # tests for the property `photoUrls` (array[character]) # uncomment below to test the property - #expect_equal(model.instance$`photo_urls`, "EXPECTED_RESULT") + #expect_equal(model.instance$`photoUrls`, "EXPECTED_RESULT") }) test_that("tags", { - # tests for the property `tags` (Tag) + # tests for the property `tags` (array[Tag]) # uncomment below to test the property #expect_equal(model.instance$`tags`, "EXPECTED_RESULT") diff --git a/samples/client/petstore/R/tests/testthat/test_pet_api.R b/samples/client/petstore/R/tests/testthat/test_pet_api.R index 021f6228af90..3388d2d63ed7 100644 --- a/samples/client/petstore/R/tests/testthat/test_pet_api.R +++ b/samples/client/petstore/R/tests/testthat/test_pet_api.R @@ -7,9 +7,9 @@ api.instance <- PetApi$new() test_that("AddPet", { # tests for AddPet + # base path: http://petstore.swagger.io/v2 # Add a new pet to the store - # @param body Pet object that needs to be added to the store - # @param [Hash] opts the optional parameters + # @param Pet body Pet object that needs to be added to the store # @return [Void] # uncomment below to test the operation @@ -18,10 +18,10 @@ test_that("AddPet", { test_that("DeletePet", { # tests for DeletePet + # base path: http://petstore.swagger.io/v2 # Deletes a pet - # @param pet.id Pet id to delete - # @param [Hash] opts the optional parameters - # @option opts [character] :api.key + # @param integer pet.id Pet id to delete + # @param character api.key (optional) # @return [Void] # uncomment below to test the operation @@ -30,11 +30,11 @@ test_that("DeletePet", { test_that("FindPetsByStatus", { # tests for FindPetsByStatus + # base path: http://petstore.swagger.io/v2 # Finds Pets by status # Multiple status values can be provided with comma separated strings - # @param status Status values that need to be considered for filter - # @param [Hash] opts the optional parameters - # @return [Pet] + # @param array[character] status Status values that need to be considered for filter + # @return [array[Pet]] # uncomment below to test the operation #expect_equal(result, "EXPECTED_RESULT") @@ -42,11 +42,11 @@ test_that("FindPetsByStatus", { test_that("FindPetsByTags", { # tests for FindPetsByTags + # base path: http://petstore.swagger.io/v2 # Finds Pets by tags # Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. - # @param tags Tags to filter by - # @param [Hash] opts the optional parameters - # @return [Pet] + # @param array[character] tags Tags to filter by + # @return [array[Pet]] # uncomment below to test the operation #expect_equal(result, "EXPECTED_RESULT") @@ -54,10 +54,10 @@ test_that("FindPetsByTags", { test_that("GetPetById", { # tests for GetPetById + # base path: http://petstore.swagger.io/v2 # Find pet by ID # Returns a single pet - # @param pet.id ID of pet to return - # @param [Hash] opts the optional parameters + # @param integer pet.id ID of pet to return # @return [Pet] # uncomment below to test the operation @@ -66,9 +66,9 @@ test_that("GetPetById", { test_that("UpdatePet", { # tests for UpdatePet + # base path: http://petstore.swagger.io/v2 # Update an existing pet - # @param body Pet object that needs to be added to the store - # @param [Hash] opts the optional parameters + # @param Pet body Pet object that needs to be added to the store # @return [Void] # uncomment below to test the operation @@ -77,11 +77,11 @@ test_that("UpdatePet", { test_that("UpdatePetWithForm", { # tests for UpdatePetWithForm + # base path: http://petstore.swagger.io/v2 # Updates a pet in the store with form data - # @param pet.id ID of pet that needs to be updated - # @param [Hash] opts the optional parameters - # @option opts [character] :name Updated name of the pet - # @option opts [character] :status Updated status of the pet + # @param integer pet.id ID of pet that needs to be updated + # @param character name Updated name of the pet (optional) + # @param character status Updated status of the pet (optional) # @return [Void] # uncomment below to test the operation @@ -90,11 +90,11 @@ test_that("UpdatePetWithForm", { test_that("UploadFile", { # tests for UploadFile + # base path: http://petstore.swagger.io/v2 # uploads an image - # @param pet.id ID of pet to update - # @param [Hash] opts the optional parameters - # @option opts [character] :additional.metadata Additional data to pass to server - # @option opts [data.frame] :file file to upload + # @param integer pet.id ID of pet to update + # @param character additional.metadata Additional data to pass to server (optional) + # @param data.frame file file to upload (optional) # @return [ModelApiResponse] # uncomment below to test the operation diff --git a/samples/client/petstore/R/tests/testthat/test_petstore.R b/samples/client/petstore/R/tests/testthat/test_petstore.R deleted file mode 100644 index 2e24b32f1241..000000000000 --- a/samples/client/petstore/R/tests/testthat/test_petstore.R +++ /dev/null @@ -1,68 +0,0 @@ -context("basic functionality") -petApi <- PetApi$new() -petId <- 123321 -test_that("AddPet", { - pet <- Pet$new("name_test", list("photo_test", "second test"), - petId, Category$new(id=450, name="test_cat"), - list(Tag$new(id=123, name="tag_test"), Tag$new(id=456, name="unknown")), - "available") - #pet <- Pet$new("name_test", - # list("photo_test", "second test"), - # category=Category$new(id=450, name="test_cat"), - # id=petId, - # tags=list(Tag$new(id=123, name="tag_test"), Tag$new(id=456, name="unknown")), - # status="available") - result <-petApi$AddPet(pet) - expect_equal(petId, 123321) - expect_equal(result, NULL) -}) - -test_that("Test Pet", { - pet <- Pet$new("name_test", list("photo_test", "second test"), - petId, Category$new(id=450, name="test_cat"), - list(Tag$new(id=123, name="tag_test"), Tag$new(id=456, name="unknown")), - "available") - - pet2 <- Pet$new() - #pet2$fromJSON(jsonlite::toJSON(pet$toJSON(), auto_unbox=TRUE)) - #expect_equal(pet, pet2) -}) - -test_that("Test Category", { - c1 <- Category$new(id=450, name="test_cat") - c2 <- Category$new() - c2$fromJSON(jsonlite::toJSON(c1$toJSON(), auto_unbox=TRUE)) - expect_equal(c1, c2) -}) - -test_that("GetPetById", { - response <- petApi$GetPetById(petId) - expect_equal(response$id, petId) - expect_equal(response$name, "name_test") - #expect_equal(response$category, Category$new(id=450, name="test_cat")) - expect_equal(response$photoUrls, list("photo_test", "second test")) - expect_equal(response$status, "available") - expect_equal(response$tags, list(Tag$new(id=123, name="tag_test"), Tag$new(id=456, name="unknown"))) -}) - -#test_that("GetPetById", { -# pet.id <- pet.id -# pet <- Pet$new(pet.id, NULL, "name_test2", -# list("photo_test2", "second test2"), -# NULL, NULL) -# result <-petApi$AddPet(pet) -# -# response <- petApi$GetPetById(pet.id) -# -# expect_equal(response$id, pet.id) -# expect_equal(response$name, "name_test2") -# #expect_equal(response$category, Category$new(450,"test_cat")) -# expect_equal(response$photoUrls, list("photo_test2", "second test2")) -# expect_equal(response$status, NULL) -# #expect_equal(response$tags, list(Tag$new(123, "tag_test"), Tag$new(456, "unknown"))) -#}) - -#test_that("updatePetWithForm", { -# response <- petApi$updatePetWithForm(petId, "test", "sold") -# expect_equal(response, "Pet updated") -#}) diff --git a/samples/client/petstore/R/tests/testthat/test_store_api.R b/samples/client/petstore/R/tests/testthat/test_store_api.R index e1290358b43f..1fe2e9eaaa86 100644 --- a/samples/client/petstore/R/tests/testthat/test_store_api.R +++ b/samples/client/petstore/R/tests/testthat/test_store_api.R @@ -7,10 +7,10 @@ api.instance <- StoreApi$new() test_that("DeleteOrder", { # tests for DeleteOrder + # base path: http://petstore.swagger.io/v2 # Delete purchase order by ID # For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors - # @param order.id ID of the order that needs to be deleted - # @param [Hash] opts the optional parameters + # @param character order.id ID of the order that needs to be deleted # @return [Void] # uncomment below to test the operation @@ -19,10 +19,10 @@ test_that("DeleteOrder", { test_that("GetInventory", { # tests for GetInventory + # base path: http://petstore.swagger.io/v2 # Returns pet inventories by status # Returns a map of status codes to quantities - # @param [Hash] opts the optional parameters - # @return [integer] + # @return [map(integer)] # uncomment below to test the operation #expect_equal(result, "EXPECTED_RESULT") @@ -30,10 +30,10 @@ test_that("GetInventory", { test_that("GetOrderById", { # tests for GetOrderById + # base path: http://petstore.swagger.io/v2 # Find purchase order by ID # For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions - # @param order.id ID of pet that needs to be fetched - # @param [Hash] opts the optional parameters + # @param integer order.id ID of pet that needs to be fetched # @return [Order] # uncomment below to test the operation @@ -42,9 +42,9 @@ test_that("GetOrderById", { test_that("PlaceOrder", { # tests for PlaceOrder + # base path: http://petstore.swagger.io/v2 # Place an order for a pet - # @param body order placed for purchasing the pet - # @param [Hash] opts the optional parameters + # @param Order body order placed for purchasing the pet # @return [Order] # uncomment below to test the operation diff --git a/samples/client/petstore/R/tests/testthat/test_user.R b/samples/client/petstore/R/tests/testthat/test_user.R index 401196a90d76..9929623b42f8 100644 --- a/samples/client/petstore/R/tests/testthat/test_user.R +++ b/samples/client/petstore/R/tests/testthat/test_user.R @@ -19,18 +19,18 @@ test_that("username", { #expect_equal(model.instance$`username`, "EXPECTED_RESULT") }) -test_that("first_name", { - # tests for the property `first_name` (character) +test_that("firstName", { + # tests for the property `firstName` (character) # uncomment below to test the property - #expect_equal(model.instance$`first_name`, "EXPECTED_RESULT") + #expect_equal(model.instance$`firstName`, "EXPECTED_RESULT") }) -test_that("last_name", { - # tests for the property `last_name` (character) +test_that("lastName", { + # tests for the property `lastName` (character) # uncomment below to test the property - #expect_equal(model.instance$`last_name`, "EXPECTED_RESULT") + #expect_equal(model.instance$`lastName`, "EXPECTED_RESULT") }) test_that("email", { @@ -54,11 +54,11 @@ test_that("phone", { #expect_equal(model.instance$`phone`, "EXPECTED_RESULT") }) -test_that("user_status", { - # tests for the property `user_status` (integer) +test_that("userStatus", { + # tests for the property `userStatus` (integer) # User Status # uncomment below to test the property - #expect_equal(model.instance$`user_status`, "EXPECTED_RESULT") + #expect_equal(model.instance$`userStatus`, "EXPECTED_RESULT") }) diff --git a/samples/client/petstore/R/tests/testthat/test_user_api.R b/samples/client/petstore/R/tests/testthat/test_user_api.R index 283c7c7e964f..8e1a0f6d4850 100644 --- a/samples/client/petstore/R/tests/testthat/test_user_api.R +++ b/samples/client/petstore/R/tests/testthat/test_user_api.R @@ -7,10 +7,10 @@ api.instance <- UserApi$new() test_that("CreateUser", { # tests for CreateUser + # base path: http://petstore.swagger.io/v2 # Create user # This can only be done by the logged in user. - # @param body Created user object - # @param [Hash] opts the optional parameters + # @param User body Created user object # @return [Void] # uncomment below to test the operation @@ -19,9 +19,9 @@ test_that("CreateUser", { test_that("CreateUsersWithArrayInput", { # tests for CreateUsersWithArrayInput + # base path: http://petstore.swagger.io/v2 # Creates list of users with given input array - # @param body List of user object - # @param [Hash] opts the optional parameters + # @param array[User] body List of user object # @return [Void] # uncomment below to test the operation @@ -30,9 +30,9 @@ test_that("CreateUsersWithArrayInput", { test_that("CreateUsersWithListInput", { # tests for CreateUsersWithListInput + # base path: http://petstore.swagger.io/v2 # Creates list of users with given input array - # @param body List of user object - # @param [Hash] opts the optional parameters + # @param array[User] body List of user object # @return [Void] # uncomment below to test the operation @@ -41,10 +41,10 @@ test_that("CreateUsersWithListInput", { test_that("DeleteUser", { # tests for DeleteUser + # base path: http://petstore.swagger.io/v2 # Delete user # This can only be done by the logged in user. - # @param username The name that needs to be deleted - # @param [Hash] opts the optional parameters + # @param character username The name that needs to be deleted # @return [Void] # uncomment below to test the operation @@ -53,9 +53,9 @@ test_that("DeleteUser", { test_that("GetUserByName", { # tests for GetUserByName + # base path: http://petstore.swagger.io/v2 # Get user by user name - # @param username The name that needs to be fetched. Use user1 for testing. - # @param [Hash] opts the optional parameters + # @param character username The name that needs to be fetched. Use user1 for testing. # @return [User] # uncomment below to test the operation @@ -64,10 +64,10 @@ test_that("GetUserByName", { test_that("LoginUser", { # tests for LoginUser + # base path: http://petstore.swagger.io/v2 # Logs user into the system - # @param username The user name for login - # @param password The password for login in clear text - # @param [Hash] opts the optional parameters + # @param character username The user name for login + # @param character password The password for login in clear text # @return [character] # uncomment below to test the operation @@ -76,8 +76,8 @@ test_that("LoginUser", { test_that("LogoutUser", { # tests for LogoutUser + # base path: http://petstore.swagger.io/v2 # Logs out current logged in user session - # @param [Hash] opts the optional parameters # @return [Void] # uncomment below to test the operation @@ -86,11 +86,11 @@ test_that("LogoutUser", { test_that("UpdateUser", { # tests for UpdateUser + # base path: http://petstore.swagger.io/v2 # Updated user # This can only be done by the logged in user. - # @param username name that need to be deleted - # @param body Updated user object - # @param [Hash] opts the optional parameters + # @param character username name that need to be deleted + # @param User body Updated user object # @return [Void] # uncomment below to test the operation From 424a97bf030abc8eb7df06fed77008eb9a8d7c7e Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Mon, 18 May 2020 12:38:41 -0400 Subject: [PATCH 21/26] Revert "update tests based on generator" This reverts commit b6314c8927a8411561577c0dfd100018947de42e. --- .../petstore/R/tests/testthat/test_order.R | 12 ++-- .../petstore/R/tests/testthat/test_pet.R | 8 +-- .../petstore/R/tests/testthat/test_pet_api.R | 46 ++++++------- .../petstore/R/tests/testthat/test_petstore.R | 68 +++++++++++++++++++ .../R/tests/testthat/test_store_api.R | 16 ++--- .../petstore/R/tests/testthat/test_user.R | 18 ++--- .../petstore/R/tests/testthat/test_user_api.R | 34 +++++----- 7 files changed, 135 insertions(+), 67 deletions(-) create mode 100644 samples/client/petstore/R/tests/testthat/test_petstore.R diff --git a/samples/client/petstore/R/tests/testthat/test_order.R b/samples/client/petstore/R/tests/testthat/test_order.R index 33b87520254d..5fb144f9372b 100644 --- a/samples/client/petstore/R/tests/testthat/test_order.R +++ b/samples/client/petstore/R/tests/testthat/test_order.R @@ -12,11 +12,11 @@ test_that("id", { #expect_equal(model.instance$`id`, "EXPECTED_RESULT") }) -test_that("petId", { - # tests for the property `petId` (integer) +test_that("pet_id", { + # tests for the property `pet_id` (integer) # uncomment below to test the property - #expect_equal(model.instance$`petId`, "EXPECTED_RESULT") + #expect_equal(model.instance$`pet_id`, "EXPECTED_RESULT") }) test_that("quantity", { @@ -26,11 +26,11 @@ test_that("quantity", { #expect_equal(model.instance$`quantity`, "EXPECTED_RESULT") }) -test_that("shipDate", { - # tests for the property `shipDate` (character) +test_that("ship_date", { + # tests for the property `ship_date` (character) # uncomment below to test the property - #expect_equal(model.instance$`shipDate`, "EXPECTED_RESULT") + #expect_equal(model.instance$`ship_date`, "EXPECTED_RESULT") }) test_that("status", { diff --git a/samples/client/petstore/R/tests/testthat/test_pet.R b/samples/client/petstore/R/tests/testthat/test_pet.R index ac3e4f31dd10..8d3ce54a55d1 100644 --- a/samples/client/petstore/R/tests/testthat/test_pet.R +++ b/samples/client/petstore/R/tests/testthat/test_pet.R @@ -26,15 +26,15 @@ test_that("name", { #expect_equal(model.instance$`name`, "EXPECTED_RESULT") }) -test_that("photoUrls", { - # tests for the property `photoUrls` (array[character]) +test_that("photo_urls", { + # tests for the property `photo_urls` (character) # uncomment below to test the property - #expect_equal(model.instance$`photoUrls`, "EXPECTED_RESULT") + #expect_equal(model.instance$`photo_urls`, "EXPECTED_RESULT") }) test_that("tags", { - # tests for the property `tags` (array[Tag]) + # tests for the property `tags` (Tag) # uncomment below to test the property #expect_equal(model.instance$`tags`, "EXPECTED_RESULT") diff --git a/samples/client/petstore/R/tests/testthat/test_pet_api.R b/samples/client/petstore/R/tests/testthat/test_pet_api.R index 3388d2d63ed7..021f6228af90 100644 --- a/samples/client/petstore/R/tests/testthat/test_pet_api.R +++ b/samples/client/petstore/R/tests/testthat/test_pet_api.R @@ -7,9 +7,9 @@ api.instance <- PetApi$new() test_that("AddPet", { # tests for AddPet - # base path: http://petstore.swagger.io/v2 # Add a new pet to the store - # @param Pet body Pet object that needs to be added to the store + # @param body Pet object that needs to be added to the store + # @param [Hash] opts the optional parameters # @return [Void] # uncomment below to test the operation @@ -18,10 +18,10 @@ test_that("AddPet", { test_that("DeletePet", { # tests for DeletePet - # base path: http://petstore.swagger.io/v2 # Deletes a pet - # @param integer pet.id Pet id to delete - # @param character api.key (optional) + # @param pet.id Pet id to delete + # @param [Hash] opts the optional parameters + # @option opts [character] :api.key # @return [Void] # uncomment below to test the operation @@ -30,11 +30,11 @@ test_that("DeletePet", { test_that("FindPetsByStatus", { # tests for FindPetsByStatus - # base path: http://petstore.swagger.io/v2 # Finds Pets by status # Multiple status values can be provided with comma separated strings - # @param array[character] status Status values that need to be considered for filter - # @return [array[Pet]] + # @param status Status values that need to be considered for filter + # @param [Hash] opts the optional parameters + # @return [Pet] # uncomment below to test the operation #expect_equal(result, "EXPECTED_RESULT") @@ -42,11 +42,11 @@ test_that("FindPetsByStatus", { test_that("FindPetsByTags", { # tests for FindPetsByTags - # base path: http://petstore.swagger.io/v2 # Finds Pets by tags # Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. - # @param array[character] tags Tags to filter by - # @return [array[Pet]] + # @param tags Tags to filter by + # @param [Hash] opts the optional parameters + # @return [Pet] # uncomment below to test the operation #expect_equal(result, "EXPECTED_RESULT") @@ -54,10 +54,10 @@ test_that("FindPetsByTags", { test_that("GetPetById", { # tests for GetPetById - # base path: http://petstore.swagger.io/v2 # Find pet by ID # Returns a single pet - # @param integer pet.id ID of pet to return + # @param pet.id ID of pet to return + # @param [Hash] opts the optional parameters # @return [Pet] # uncomment below to test the operation @@ -66,9 +66,9 @@ test_that("GetPetById", { test_that("UpdatePet", { # tests for UpdatePet - # base path: http://petstore.swagger.io/v2 # Update an existing pet - # @param Pet body Pet object that needs to be added to the store + # @param body Pet object that needs to be added to the store + # @param [Hash] opts the optional parameters # @return [Void] # uncomment below to test the operation @@ -77,11 +77,11 @@ test_that("UpdatePet", { test_that("UpdatePetWithForm", { # tests for UpdatePetWithForm - # base path: http://petstore.swagger.io/v2 # Updates a pet in the store with form data - # @param integer pet.id ID of pet that needs to be updated - # @param character name Updated name of the pet (optional) - # @param character status Updated status of the pet (optional) + # @param pet.id ID of pet that needs to be updated + # @param [Hash] opts the optional parameters + # @option opts [character] :name Updated name of the pet + # @option opts [character] :status Updated status of the pet # @return [Void] # uncomment below to test the operation @@ -90,11 +90,11 @@ test_that("UpdatePetWithForm", { test_that("UploadFile", { # tests for UploadFile - # base path: http://petstore.swagger.io/v2 # uploads an image - # @param integer pet.id ID of pet to update - # @param character additional.metadata Additional data to pass to server (optional) - # @param data.frame file file to upload (optional) + # @param pet.id ID of pet to update + # @param [Hash] opts the optional parameters + # @option opts [character] :additional.metadata Additional data to pass to server + # @option opts [data.frame] :file file to upload # @return [ModelApiResponse] # uncomment below to test the operation diff --git a/samples/client/petstore/R/tests/testthat/test_petstore.R b/samples/client/petstore/R/tests/testthat/test_petstore.R new file mode 100644 index 000000000000..2e24b32f1241 --- /dev/null +++ b/samples/client/petstore/R/tests/testthat/test_petstore.R @@ -0,0 +1,68 @@ +context("basic functionality") +petApi <- PetApi$new() +petId <- 123321 +test_that("AddPet", { + pet <- Pet$new("name_test", list("photo_test", "second test"), + petId, Category$new(id=450, name="test_cat"), + list(Tag$new(id=123, name="tag_test"), Tag$new(id=456, name="unknown")), + "available") + #pet <- Pet$new("name_test", + # list("photo_test", "second test"), + # category=Category$new(id=450, name="test_cat"), + # id=petId, + # tags=list(Tag$new(id=123, name="tag_test"), Tag$new(id=456, name="unknown")), + # status="available") + result <-petApi$AddPet(pet) + expect_equal(petId, 123321) + expect_equal(result, NULL) +}) + +test_that("Test Pet", { + pet <- Pet$new("name_test", list("photo_test", "second test"), + petId, Category$new(id=450, name="test_cat"), + list(Tag$new(id=123, name="tag_test"), Tag$new(id=456, name="unknown")), + "available") + + pet2 <- Pet$new() + #pet2$fromJSON(jsonlite::toJSON(pet$toJSON(), auto_unbox=TRUE)) + #expect_equal(pet, pet2) +}) + +test_that("Test Category", { + c1 <- Category$new(id=450, name="test_cat") + c2 <- Category$new() + c2$fromJSON(jsonlite::toJSON(c1$toJSON(), auto_unbox=TRUE)) + expect_equal(c1, c2) +}) + +test_that("GetPetById", { + response <- petApi$GetPetById(petId) + expect_equal(response$id, petId) + expect_equal(response$name, "name_test") + #expect_equal(response$category, Category$new(id=450, name="test_cat")) + expect_equal(response$photoUrls, list("photo_test", "second test")) + expect_equal(response$status, "available") + expect_equal(response$tags, list(Tag$new(id=123, name="tag_test"), Tag$new(id=456, name="unknown"))) +}) + +#test_that("GetPetById", { +# pet.id <- pet.id +# pet <- Pet$new(pet.id, NULL, "name_test2", +# list("photo_test2", "second test2"), +# NULL, NULL) +# result <-petApi$AddPet(pet) +# +# response <- petApi$GetPetById(pet.id) +# +# expect_equal(response$id, pet.id) +# expect_equal(response$name, "name_test2") +# #expect_equal(response$category, Category$new(450,"test_cat")) +# expect_equal(response$photoUrls, list("photo_test2", "second test2")) +# expect_equal(response$status, NULL) +# #expect_equal(response$tags, list(Tag$new(123, "tag_test"), Tag$new(456, "unknown"))) +#}) + +#test_that("updatePetWithForm", { +# response <- petApi$updatePetWithForm(petId, "test", "sold") +# expect_equal(response, "Pet updated") +#}) diff --git a/samples/client/petstore/R/tests/testthat/test_store_api.R b/samples/client/petstore/R/tests/testthat/test_store_api.R index 1fe2e9eaaa86..e1290358b43f 100644 --- a/samples/client/petstore/R/tests/testthat/test_store_api.R +++ b/samples/client/petstore/R/tests/testthat/test_store_api.R @@ -7,10 +7,10 @@ api.instance <- StoreApi$new() test_that("DeleteOrder", { # tests for DeleteOrder - # base path: http://petstore.swagger.io/v2 # Delete purchase order by ID # For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors - # @param character order.id ID of the order that needs to be deleted + # @param order.id ID of the order that needs to be deleted + # @param [Hash] opts the optional parameters # @return [Void] # uncomment below to test the operation @@ -19,10 +19,10 @@ test_that("DeleteOrder", { test_that("GetInventory", { # tests for GetInventory - # base path: http://petstore.swagger.io/v2 # Returns pet inventories by status # Returns a map of status codes to quantities - # @return [map(integer)] + # @param [Hash] opts the optional parameters + # @return [integer] # uncomment below to test the operation #expect_equal(result, "EXPECTED_RESULT") @@ -30,10 +30,10 @@ test_that("GetInventory", { test_that("GetOrderById", { # tests for GetOrderById - # base path: http://petstore.swagger.io/v2 # Find purchase order by ID # For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions - # @param integer order.id ID of pet that needs to be fetched + # @param order.id ID of pet that needs to be fetched + # @param [Hash] opts the optional parameters # @return [Order] # uncomment below to test the operation @@ -42,9 +42,9 @@ test_that("GetOrderById", { test_that("PlaceOrder", { # tests for PlaceOrder - # base path: http://petstore.swagger.io/v2 # Place an order for a pet - # @param Order body order placed for purchasing the pet + # @param body order placed for purchasing the pet + # @param [Hash] opts the optional parameters # @return [Order] # uncomment below to test the operation diff --git a/samples/client/petstore/R/tests/testthat/test_user.R b/samples/client/petstore/R/tests/testthat/test_user.R index 9929623b42f8..401196a90d76 100644 --- a/samples/client/petstore/R/tests/testthat/test_user.R +++ b/samples/client/petstore/R/tests/testthat/test_user.R @@ -19,18 +19,18 @@ test_that("username", { #expect_equal(model.instance$`username`, "EXPECTED_RESULT") }) -test_that("firstName", { - # tests for the property `firstName` (character) +test_that("first_name", { + # tests for the property `first_name` (character) # uncomment below to test the property - #expect_equal(model.instance$`firstName`, "EXPECTED_RESULT") + #expect_equal(model.instance$`first_name`, "EXPECTED_RESULT") }) -test_that("lastName", { - # tests for the property `lastName` (character) +test_that("last_name", { + # tests for the property `last_name` (character) # uncomment below to test the property - #expect_equal(model.instance$`lastName`, "EXPECTED_RESULT") + #expect_equal(model.instance$`last_name`, "EXPECTED_RESULT") }) test_that("email", { @@ -54,11 +54,11 @@ test_that("phone", { #expect_equal(model.instance$`phone`, "EXPECTED_RESULT") }) -test_that("userStatus", { - # tests for the property `userStatus` (integer) +test_that("user_status", { + # tests for the property `user_status` (integer) # User Status # uncomment below to test the property - #expect_equal(model.instance$`userStatus`, "EXPECTED_RESULT") + #expect_equal(model.instance$`user_status`, "EXPECTED_RESULT") }) diff --git a/samples/client/petstore/R/tests/testthat/test_user_api.R b/samples/client/petstore/R/tests/testthat/test_user_api.R index 8e1a0f6d4850..283c7c7e964f 100644 --- a/samples/client/petstore/R/tests/testthat/test_user_api.R +++ b/samples/client/petstore/R/tests/testthat/test_user_api.R @@ -7,10 +7,10 @@ api.instance <- UserApi$new() test_that("CreateUser", { # tests for CreateUser - # base path: http://petstore.swagger.io/v2 # Create user # This can only be done by the logged in user. - # @param User body Created user object + # @param body Created user object + # @param [Hash] opts the optional parameters # @return [Void] # uncomment below to test the operation @@ -19,9 +19,9 @@ test_that("CreateUser", { test_that("CreateUsersWithArrayInput", { # tests for CreateUsersWithArrayInput - # base path: http://petstore.swagger.io/v2 # Creates list of users with given input array - # @param array[User] body List of user object + # @param body List of user object + # @param [Hash] opts the optional parameters # @return [Void] # uncomment below to test the operation @@ -30,9 +30,9 @@ test_that("CreateUsersWithArrayInput", { test_that("CreateUsersWithListInput", { # tests for CreateUsersWithListInput - # base path: http://petstore.swagger.io/v2 # Creates list of users with given input array - # @param array[User] body List of user object + # @param body List of user object + # @param [Hash] opts the optional parameters # @return [Void] # uncomment below to test the operation @@ -41,10 +41,10 @@ test_that("CreateUsersWithListInput", { test_that("DeleteUser", { # tests for DeleteUser - # base path: http://petstore.swagger.io/v2 # Delete user # This can only be done by the logged in user. - # @param character username The name that needs to be deleted + # @param username The name that needs to be deleted + # @param [Hash] opts the optional parameters # @return [Void] # uncomment below to test the operation @@ -53,9 +53,9 @@ test_that("DeleteUser", { test_that("GetUserByName", { # tests for GetUserByName - # base path: http://petstore.swagger.io/v2 # Get user by user name - # @param character username The name that needs to be fetched. Use user1 for testing. + # @param username The name that needs to be fetched. Use user1 for testing. + # @param [Hash] opts the optional parameters # @return [User] # uncomment below to test the operation @@ -64,10 +64,10 @@ test_that("GetUserByName", { test_that("LoginUser", { # tests for LoginUser - # base path: http://petstore.swagger.io/v2 # Logs user into the system - # @param character username The user name for login - # @param character password The password for login in clear text + # @param username The user name for login + # @param password The password for login in clear text + # @param [Hash] opts the optional parameters # @return [character] # uncomment below to test the operation @@ -76,8 +76,8 @@ test_that("LoginUser", { test_that("LogoutUser", { # tests for LogoutUser - # base path: http://petstore.swagger.io/v2 # Logs out current logged in user session + # @param [Hash] opts the optional parameters # @return [Void] # uncomment below to test the operation @@ -86,11 +86,11 @@ test_that("LogoutUser", { test_that("UpdateUser", { # tests for UpdateUser - # base path: http://petstore.swagger.io/v2 # Updated user # This can only be done by the logged in user. - # @param character username name that need to be deleted - # @param User body Updated user object + # @param username name that need to be deleted + # @param body Updated user object + # @param [Hash] opts the optional parameters # @return [Void] # uncomment below to test the operation From c703965ef70fdd807f2ea1cabec63cba800561de Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Mon, 18 May 2020 13:26:58 -0400 Subject: [PATCH 22/26] Update tests with engine - preserve test_petstore.R --- .../src/main/resources/r/api_test.mustache | 2 +- .../petstore/R/tests/testthat/test_order.R | 12 ++--- .../petstore/R/tests/testthat/test_pet.R | 8 ++-- .../petstore/R/tests/testthat/test_pet_api.R | 46 +++++++++---------- .../R/tests/testthat/test_store_api.R | 16 +++---- .../petstore/R/tests/testthat/test_user.R | 18 ++++---- .../petstore/R/tests/testthat/test_user_api.R | 34 +++++++------- samples/client/petstore/R/testthat.R | 4 -- 8 files changed, 68 insertions(+), 72 deletions(-) delete mode 100644 samples/client/petstore/R/testthat.R diff --git a/modules/openapi-generator/src/main/resources/r/api_test.mustache b/modules/openapi-generator/src/main/resources/r/api_test.mustache index 6b0bbcf87164..1b7e184d85fb 100644 --- a/modules/openapi-generator/src/main/resources/r/api_test.mustache +++ b/modules/openapi-generator/src/main/resources/r/api_test.mustache @@ -17,7 +17,7 @@ test_that("{{{operationId}}}", { # {{notes}} {{/notes}} {{#allParams}} - # @param {{{dataType}}} {{{paramName}}} {{{description}}} {{^required}} (optional){{/required}} + # @param {{{paramName}}} {{{dataType}}} {{{description}}}{{^required}} (optional){{/required}} {{/allParams}} # @return [{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}] diff --git a/samples/client/petstore/R/tests/testthat/test_order.R b/samples/client/petstore/R/tests/testthat/test_order.R index 5fb144f9372b..33b87520254d 100644 --- a/samples/client/petstore/R/tests/testthat/test_order.R +++ b/samples/client/petstore/R/tests/testthat/test_order.R @@ -12,11 +12,11 @@ test_that("id", { #expect_equal(model.instance$`id`, "EXPECTED_RESULT") }) -test_that("pet_id", { - # tests for the property `pet_id` (integer) +test_that("petId", { + # tests for the property `petId` (integer) # uncomment below to test the property - #expect_equal(model.instance$`pet_id`, "EXPECTED_RESULT") + #expect_equal(model.instance$`petId`, "EXPECTED_RESULT") }) test_that("quantity", { @@ -26,11 +26,11 @@ test_that("quantity", { #expect_equal(model.instance$`quantity`, "EXPECTED_RESULT") }) -test_that("ship_date", { - # tests for the property `ship_date` (character) +test_that("shipDate", { + # tests for the property `shipDate` (character) # uncomment below to test the property - #expect_equal(model.instance$`ship_date`, "EXPECTED_RESULT") + #expect_equal(model.instance$`shipDate`, "EXPECTED_RESULT") }) test_that("status", { diff --git a/samples/client/petstore/R/tests/testthat/test_pet.R b/samples/client/petstore/R/tests/testthat/test_pet.R index 8d3ce54a55d1..ac3e4f31dd10 100644 --- a/samples/client/petstore/R/tests/testthat/test_pet.R +++ b/samples/client/petstore/R/tests/testthat/test_pet.R @@ -26,15 +26,15 @@ test_that("name", { #expect_equal(model.instance$`name`, "EXPECTED_RESULT") }) -test_that("photo_urls", { - # tests for the property `photo_urls` (character) +test_that("photoUrls", { + # tests for the property `photoUrls` (array[character]) # uncomment below to test the property - #expect_equal(model.instance$`photo_urls`, "EXPECTED_RESULT") + #expect_equal(model.instance$`photoUrls`, "EXPECTED_RESULT") }) test_that("tags", { - # tests for the property `tags` (Tag) + # tests for the property `tags` (array[Tag]) # uncomment below to test the property #expect_equal(model.instance$`tags`, "EXPECTED_RESULT") diff --git a/samples/client/petstore/R/tests/testthat/test_pet_api.R b/samples/client/petstore/R/tests/testthat/test_pet_api.R index 021f6228af90..7fbdd1a70deb 100644 --- a/samples/client/petstore/R/tests/testthat/test_pet_api.R +++ b/samples/client/petstore/R/tests/testthat/test_pet_api.R @@ -7,9 +7,9 @@ api.instance <- PetApi$new() test_that("AddPet", { # tests for AddPet + # base path: http://petstore.swagger.io/v2 # Add a new pet to the store - # @param body Pet object that needs to be added to the store - # @param [Hash] opts the optional parameters + # @param body Pet Pet object that needs to be added to the store # @return [Void] # uncomment below to test the operation @@ -18,10 +18,10 @@ test_that("AddPet", { test_that("DeletePet", { # tests for DeletePet + # base path: http://petstore.swagger.io/v2 # Deletes a pet - # @param pet.id Pet id to delete - # @param [Hash] opts the optional parameters - # @option opts [character] :api.key + # @param pet.id integer Pet id to delete + # @param api.key character (optional) # @return [Void] # uncomment below to test the operation @@ -30,11 +30,11 @@ test_that("DeletePet", { test_that("FindPetsByStatus", { # tests for FindPetsByStatus + # base path: http://petstore.swagger.io/v2 # Finds Pets by status # Multiple status values can be provided with comma separated strings - # @param status Status values that need to be considered for filter - # @param [Hash] opts the optional parameters - # @return [Pet] + # @param status array[character] Status values that need to be considered for filter + # @return [array[Pet]] # uncomment below to test the operation #expect_equal(result, "EXPECTED_RESULT") @@ -42,11 +42,11 @@ test_that("FindPetsByStatus", { test_that("FindPetsByTags", { # tests for FindPetsByTags + # base path: http://petstore.swagger.io/v2 # Finds Pets by tags # Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. - # @param tags Tags to filter by - # @param [Hash] opts the optional parameters - # @return [Pet] + # @param tags array[character] Tags to filter by + # @return [array[Pet]] # uncomment below to test the operation #expect_equal(result, "EXPECTED_RESULT") @@ -54,10 +54,10 @@ test_that("FindPetsByTags", { test_that("GetPetById", { # tests for GetPetById + # base path: http://petstore.swagger.io/v2 # Find pet by ID # Returns a single pet - # @param pet.id ID of pet to return - # @param [Hash] opts the optional parameters + # @param pet.id integer ID of pet to return # @return [Pet] # uncomment below to test the operation @@ -66,9 +66,9 @@ test_that("GetPetById", { test_that("UpdatePet", { # tests for UpdatePet + # base path: http://petstore.swagger.io/v2 # Update an existing pet - # @param body Pet object that needs to be added to the store - # @param [Hash] opts the optional parameters + # @param body Pet Pet object that needs to be added to the store # @return [Void] # uncomment below to test the operation @@ -77,11 +77,11 @@ test_that("UpdatePet", { test_that("UpdatePetWithForm", { # tests for UpdatePetWithForm + # base path: http://petstore.swagger.io/v2 # Updates a pet in the store with form data - # @param pet.id ID of pet that needs to be updated - # @param [Hash] opts the optional parameters - # @option opts [character] :name Updated name of the pet - # @option opts [character] :status Updated status of the pet + # @param pet.id integer ID of pet that needs to be updated + # @param name character Updated name of the pet (optional) + # @param status character Updated status of the pet (optional) # @return [Void] # uncomment below to test the operation @@ -90,11 +90,11 @@ test_that("UpdatePetWithForm", { test_that("UploadFile", { # tests for UploadFile + # base path: http://petstore.swagger.io/v2 # uploads an image - # @param pet.id ID of pet to update - # @param [Hash] opts the optional parameters - # @option opts [character] :additional.metadata Additional data to pass to server - # @option opts [data.frame] :file file to upload + # @param pet.id integer ID of pet to update + # @param additional.metadata character Additional data to pass to server (optional) + # @param file data.frame file to upload (optional) # @return [ModelApiResponse] # uncomment below to test the operation diff --git a/samples/client/petstore/R/tests/testthat/test_store_api.R b/samples/client/petstore/R/tests/testthat/test_store_api.R index e1290358b43f..1ebb3f82a639 100644 --- a/samples/client/petstore/R/tests/testthat/test_store_api.R +++ b/samples/client/petstore/R/tests/testthat/test_store_api.R @@ -7,10 +7,10 @@ api.instance <- StoreApi$new() test_that("DeleteOrder", { # tests for DeleteOrder + # base path: http://petstore.swagger.io/v2 # Delete purchase order by ID # For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors - # @param order.id ID of the order that needs to be deleted - # @param [Hash] opts the optional parameters + # @param order.id character ID of the order that needs to be deleted # @return [Void] # uncomment below to test the operation @@ -19,10 +19,10 @@ test_that("DeleteOrder", { test_that("GetInventory", { # tests for GetInventory + # base path: http://petstore.swagger.io/v2 # Returns pet inventories by status # Returns a map of status codes to quantities - # @param [Hash] opts the optional parameters - # @return [integer] + # @return [map(integer)] # uncomment below to test the operation #expect_equal(result, "EXPECTED_RESULT") @@ -30,10 +30,10 @@ test_that("GetInventory", { test_that("GetOrderById", { # tests for GetOrderById + # base path: http://petstore.swagger.io/v2 # Find purchase order by ID # For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions - # @param order.id ID of pet that needs to be fetched - # @param [Hash] opts the optional parameters + # @param order.id integer ID of pet that needs to be fetched # @return [Order] # uncomment below to test the operation @@ -42,9 +42,9 @@ test_that("GetOrderById", { test_that("PlaceOrder", { # tests for PlaceOrder + # base path: http://petstore.swagger.io/v2 # Place an order for a pet - # @param body order placed for purchasing the pet - # @param [Hash] opts the optional parameters + # @param body Order order placed for purchasing the pet # @return [Order] # uncomment below to test the operation diff --git a/samples/client/petstore/R/tests/testthat/test_user.R b/samples/client/petstore/R/tests/testthat/test_user.R index 401196a90d76..9929623b42f8 100644 --- a/samples/client/petstore/R/tests/testthat/test_user.R +++ b/samples/client/petstore/R/tests/testthat/test_user.R @@ -19,18 +19,18 @@ test_that("username", { #expect_equal(model.instance$`username`, "EXPECTED_RESULT") }) -test_that("first_name", { - # tests for the property `first_name` (character) +test_that("firstName", { + # tests for the property `firstName` (character) # uncomment below to test the property - #expect_equal(model.instance$`first_name`, "EXPECTED_RESULT") + #expect_equal(model.instance$`firstName`, "EXPECTED_RESULT") }) -test_that("last_name", { - # tests for the property `last_name` (character) +test_that("lastName", { + # tests for the property `lastName` (character) # uncomment below to test the property - #expect_equal(model.instance$`last_name`, "EXPECTED_RESULT") + #expect_equal(model.instance$`lastName`, "EXPECTED_RESULT") }) test_that("email", { @@ -54,11 +54,11 @@ test_that("phone", { #expect_equal(model.instance$`phone`, "EXPECTED_RESULT") }) -test_that("user_status", { - # tests for the property `user_status` (integer) +test_that("userStatus", { + # tests for the property `userStatus` (integer) # User Status # uncomment below to test the property - #expect_equal(model.instance$`user_status`, "EXPECTED_RESULT") + #expect_equal(model.instance$`userStatus`, "EXPECTED_RESULT") }) diff --git a/samples/client/petstore/R/tests/testthat/test_user_api.R b/samples/client/petstore/R/tests/testthat/test_user_api.R index 283c7c7e964f..8b8c3ba38477 100644 --- a/samples/client/petstore/R/tests/testthat/test_user_api.R +++ b/samples/client/petstore/R/tests/testthat/test_user_api.R @@ -7,10 +7,10 @@ api.instance <- UserApi$new() test_that("CreateUser", { # tests for CreateUser + # base path: http://petstore.swagger.io/v2 # Create user # This can only be done by the logged in user. - # @param body Created user object - # @param [Hash] opts the optional parameters + # @param body User Created user object # @return [Void] # uncomment below to test the operation @@ -19,9 +19,9 @@ test_that("CreateUser", { test_that("CreateUsersWithArrayInput", { # tests for CreateUsersWithArrayInput + # base path: http://petstore.swagger.io/v2 # Creates list of users with given input array - # @param body List of user object - # @param [Hash] opts the optional parameters + # @param body array[User] List of user object # @return [Void] # uncomment below to test the operation @@ -30,9 +30,9 @@ test_that("CreateUsersWithArrayInput", { test_that("CreateUsersWithListInput", { # tests for CreateUsersWithListInput + # base path: http://petstore.swagger.io/v2 # Creates list of users with given input array - # @param body List of user object - # @param [Hash] opts the optional parameters + # @param body array[User] List of user object # @return [Void] # uncomment below to test the operation @@ -41,10 +41,10 @@ test_that("CreateUsersWithListInput", { test_that("DeleteUser", { # tests for DeleteUser + # base path: http://petstore.swagger.io/v2 # Delete user # This can only be done by the logged in user. - # @param username The name that needs to be deleted - # @param [Hash] opts the optional parameters + # @param username character The name that needs to be deleted # @return [Void] # uncomment below to test the operation @@ -53,9 +53,9 @@ test_that("DeleteUser", { test_that("GetUserByName", { # tests for GetUserByName + # base path: http://petstore.swagger.io/v2 # Get user by user name - # @param username The name that needs to be fetched. Use user1 for testing. - # @param [Hash] opts the optional parameters + # @param username character The name that needs to be fetched. Use user1 for testing. # @return [User] # uncomment below to test the operation @@ -64,10 +64,10 @@ test_that("GetUserByName", { test_that("LoginUser", { # tests for LoginUser + # base path: http://petstore.swagger.io/v2 # Logs user into the system - # @param username The user name for login - # @param password The password for login in clear text - # @param [Hash] opts the optional parameters + # @param username character The user name for login + # @param password character The password for login in clear text # @return [character] # uncomment below to test the operation @@ -76,8 +76,8 @@ test_that("LoginUser", { test_that("LogoutUser", { # tests for LogoutUser + # base path: http://petstore.swagger.io/v2 # Logs out current logged in user session - # @param [Hash] opts the optional parameters # @return [Void] # uncomment below to test the operation @@ -86,11 +86,11 @@ test_that("LogoutUser", { test_that("UpdateUser", { # tests for UpdateUser + # base path: http://petstore.swagger.io/v2 # Updated user # This can only be done by the logged in user. - # @param username name that need to be deleted - # @param body Updated user object - # @param [Hash] opts the optional parameters + # @param username character name that need to be deleted + # @param body User Updated user object # @return [Void] # uncomment below to test the operation diff --git a/samples/client/petstore/R/testthat.R b/samples/client/petstore/R/testthat.R deleted file mode 100644 index d67bd9cf2380..000000000000 --- a/samples/client/petstore/R/testthat.R +++ /dev/null @@ -1,4 +0,0 @@ -library(testthat) -library(petstore) - -test_check("petstore") From 867eced9bd1f409c36faca6f59f98d5ee0fc8730 Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Tue, 19 May 2020 14:13:20 -0400 Subject: [PATCH 23/26] restore apiResponse --- .../src/main/resources/r/api.mustache | 2 +- samples/client/petstore/R/R/pet_api.R | 16 ++++++++-------- samples/client/petstore/R/R/store_api.R | 8 ++++---- samples/client/petstore/R/R/user_api.R | 16 ++++++++-------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/r/api.mustache b/modules/openapi-generator/src/main/resources/r/api.mustache index f6a77968abf0..2fd462e13786 100644 --- a/modules/openapi-generator/src/main/resources/r/api.mustache +++ b/modules/openapi-generator/src/main/resources/r/api.mustache @@ -163,7 +163,7 @@ apiResponse <- self${{{operationId}}}WithHttpInfo({{#allParams}}{{paramName}}, {{/allParams}}...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - httr::content(resp) + apiResponse$content } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { diff --git a/samples/client/petstore/R/R/pet_api.R b/samples/client/petstore/R/R/pet_api.R index 133ce8cb27a9..9fad358f4f9e 100644 --- a/samples/client/petstore/R/R/pet_api.R +++ b/samples/client/petstore/R/R/pet_api.R @@ -335,7 +335,7 @@ PetApi <- R6::R6Class( apiResponse <- self$AddPetWithHttpInfo(body, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - httr::content(resp) + apiResponse$content } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -385,7 +385,7 @@ PetApi <- R6::R6Class( apiResponse <- self$DeletePetWithHttpInfo(pet.id, api.key, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - httr::content(resp) + apiResponse$content } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -435,7 +435,7 @@ PetApi <- R6::R6Class( apiResponse <- self$FindPetsByStatusWithHttpInfo(status, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - httr::content(resp) + apiResponse$content } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -487,7 +487,7 @@ PetApi <- R6::R6Class( apiResponse <- self$FindPetsByTagsWithHttpInfo(tags, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - httr::content(resp) + apiResponse$content } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -539,7 +539,7 @@ PetApi <- R6::R6Class( apiResponse <- self$GetPetByIdWithHttpInfo(pet.id, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - httr::content(resp) + apiResponse$content } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -595,7 +595,7 @@ PetApi <- R6::R6Class( apiResponse <- self$UpdatePetWithHttpInfo(body, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - httr::content(resp) + apiResponse$content } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -645,7 +645,7 @@ PetApi <- R6::R6Class( apiResponse <- self$UpdatePetWithFormWithHttpInfo(pet.id, name, status, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - httr::content(resp) + apiResponse$content } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -698,7 +698,7 @@ PetApi <- R6::R6Class( apiResponse <- self$UploadFileWithHttpInfo(pet.id, additional.metadata, file, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - httr::content(resp) + apiResponse$content } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { diff --git a/samples/client/petstore/R/R/store_api.R b/samples/client/petstore/R/R/store_api.R index 409a8080bf6f..ba525799db51 100644 --- a/samples/client/petstore/R/R/store_api.R +++ b/samples/client/petstore/R/R/store_api.R @@ -178,7 +178,7 @@ StoreApi <- R6::R6Class( apiResponse <- self$DeleteOrderWithHttpInfo(order.id, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - httr::content(resp) + apiResponse$content } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -224,7 +224,7 @@ StoreApi <- R6::R6Class( apiResponse <- self$GetInventoryWithHttpInfo(...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - httr::content(resp) + apiResponse$content } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -272,7 +272,7 @@ StoreApi <- R6::R6Class( apiResponse <- self$GetOrderByIdWithHttpInfo(order.id, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - httr::content(resp) + apiResponse$content } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -324,7 +324,7 @@ StoreApi <- R6::R6Class( apiResponse <- self$PlaceOrderWithHttpInfo(body, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - httr::content(resp) + apiResponse$content } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { diff --git a/samples/client/petstore/R/R/user_api.R b/samples/client/petstore/R/R/user_api.R index b8e03881440b..4c4afbeb72bf 100644 --- a/samples/client/petstore/R/R/user_api.R +++ b/samples/client/petstore/R/R/user_api.R @@ -295,7 +295,7 @@ UserApi <- R6::R6Class( apiResponse <- self$CreateUserWithHttpInfo(body, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - httr::content(resp) + apiResponse$content } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -343,7 +343,7 @@ UserApi <- R6::R6Class( apiResponse <- self$CreateUsersWithArrayInputWithHttpInfo(body, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - httr::content(resp) + apiResponse$content } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -392,7 +392,7 @@ UserApi <- R6::R6Class( apiResponse <- self$CreateUsersWithListInputWithHttpInfo(body, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - httr::content(resp) + apiResponse$content } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -441,7 +441,7 @@ UserApi <- R6::R6Class( apiResponse <- self$DeleteUserWithHttpInfo(username, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - httr::content(resp) + apiResponse$content } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -487,7 +487,7 @@ UserApi <- R6::R6Class( apiResponse <- self$GetUserByNameWithHttpInfo(username, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - httr::content(resp) + apiResponse$content } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -539,7 +539,7 @@ UserApi <- R6::R6Class( apiResponse <- self$LoginUserWithHttpInfo(username, password, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - httr::content(resp) + apiResponse$content } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -595,7 +595,7 @@ UserApi <- R6::R6Class( apiResponse <- self$LogoutUserWithHttpInfo(...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - httr::content(resp) + apiResponse$content } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { @@ -633,7 +633,7 @@ UserApi <- R6::R6Class( apiResponse <- self$UpdateUserWithHttpInfo(username, body, ...) resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - httr::content(resp) + apiResponse$content } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { From dafb94f3ab3d6ba9ebea96a8e32123ddced1202d Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Tue, 19 May 2020 14:19:05 -0400 Subject: [PATCH 24/26] restore simplifyVector to TRUE value --- .../openapi-generator/src/main/resources/r/model.mustache | 6 ++---- samples/client/petstore/R/R/category.R | 6 ++---- samples/client/petstore/R/R/model_api_response.R | 6 ++---- samples/client/petstore/R/R/order.R | 6 ++---- samples/client/petstore/R/R/pet.R | 6 ++---- samples/client/petstore/R/R/tag.R | 6 ++---- samples/client/petstore/R/R/user.R | 6 ++---- 7 files changed, 14 insertions(+), 28 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/r/model.mustache b/modules/openapi-generator/src/main/resources/r/model.mustache index 1466edb6b0b3..aba9d1b987be 100644 --- a/modules/openapi-generator/src/main/resources/r/model.mustache +++ b/modules/openapi-generator/src/main/resources/r/model.mustache @@ -149,8 +149,7 @@ {{classname}}Object }, fromJSON = function({{classname}}Json) { - {{classname}}Object <- jsonlite::fromJSON({{classname}}Json, - simplifyVector = FALSE) + {{classname}}Object <- jsonlite::fromJSON({{classname}}Json) {{#vars}} if (!is.null({{classname}}Object$`{{baseName}}`)) { {{#isContainer}} @@ -232,8 +231,7 @@ paste('{', jsoncontent, '}', sep = "") }, fromJSONString = function({{classname}}Json) { - {{classname}}Object <- jsonlite::fromJSON({{classname}}Json, - simplifyVector = FALSE) + {{classname}}Object <- jsonlite::fromJSON({{classname}}Json) {{#vars}} {{! AAPI - added condition for handling container type of parameters, map and array}} {{#isContainer}} diff --git a/samples/client/petstore/R/R/category.R b/samples/client/petstore/R/R/category.R index 361917d6aab5..7c74320d1acf 100644 --- a/samples/client/petstore/R/R/category.R +++ b/samples/client/petstore/R/R/category.R @@ -52,8 +52,7 @@ Category <- R6::R6Class( CategoryObject }, fromJSON = function(CategoryJson) { - CategoryObject <- jsonlite::fromJSON(CategoryJson, - simplifyVector = FALSE) + CategoryObject <- jsonlite::fromJSON(CategoryJson) if (!is.null(CategoryObject$`id`)) { self$`id` <- CategoryObject$`id` } @@ -83,8 +82,7 @@ Category <- R6::R6Class( paste('{', jsoncontent, '}', sep = "") }, fromJSONString = function(CategoryJson) { - CategoryObject <- jsonlite::fromJSON(CategoryJson, - simplifyVector = FALSE) + CategoryObject <- jsonlite::fromJSON(CategoryJson) self$`id` <- CategoryObject$`id` self$`name` <- CategoryObject$`name` self diff --git a/samples/client/petstore/R/R/model_api_response.R b/samples/client/petstore/R/R/model_api_response.R index f2efc696d6ff..c7cdbb76c2a4 100644 --- a/samples/client/petstore/R/R/model_api_response.R +++ b/samples/client/petstore/R/R/model_api_response.R @@ -63,8 +63,7 @@ ModelApiResponse <- R6::R6Class( ModelApiResponseObject }, fromJSON = function(ModelApiResponseJson) { - ModelApiResponseObject <- jsonlite::fromJSON(ModelApiResponseJson, - simplifyVector = FALSE) + ModelApiResponseObject <- jsonlite::fromJSON(ModelApiResponseJson) if (!is.null(ModelApiResponseObject$`code`)) { self$`code` <- ModelApiResponseObject$`code` } @@ -104,8 +103,7 @@ ModelApiResponse <- R6::R6Class( paste('{', jsoncontent, '}', sep = "") }, fromJSONString = function(ModelApiResponseJson) { - ModelApiResponseObject <- jsonlite::fromJSON(ModelApiResponseJson, - simplifyVector = FALSE) + ModelApiResponseObject <- jsonlite::fromJSON(ModelApiResponseJson) self$`code` <- ModelApiResponseObject$`code` self$`type` <- ModelApiResponseObject$`type` self$`message` <- ModelApiResponseObject$`message` diff --git a/samples/client/petstore/R/R/order.R b/samples/client/petstore/R/R/order.R index 0b17d711f9d0..3218835cc35c 100644 --- a/samples/client/petstore/R/R/order.R +++ b/samples/client/petstore/R/R/order.R @@ -95,8 +95,7 @@ Order <- R6::R6Class( OrderObject }, fromJSON = function(OrderJson) { - OrderObject <- jsonlite::fromJSON(OrderJson, - simplifyVector = FALSE) + OrderObject <- jsonlite::fromJSON(OrderJson) if (!is.null(OrderObject$`id`)) { self$`id` <- OrderObject$`id` } @@ -166,8 +165,7 @@ Order <- R6::R6Class( paste('{', jsoncontent, '}', sep = "") }, fromJSONString = function(OrderJson) { - OrderObject <- jsonlite::fromJSON(OrderJson, - simplifyVector = FALSE) + OrderObject <- jsonlite::fromJSON(OrderJson) self$`id` <- OrderObject$`id` self$`petId` <- OrderObject$`petId` self$`quantity` <- OrderObject$`quantity` diff --git a/samples/client/petstore/R/R/pet.R b/samples/client/petstore/R/R/pet.R index 90bcdf1762d0..509d16934e1f 100644 --- a/samples/client/petstore/R/R/pet.R +++ b/samples/client/petstore/R/R/pet.R @@ -98,8 +98,7 @@ Pet <- R6::R6Class( PetObject }, fromJSON = function(PetJson) { - PetObject <- jsonlite::fromJSON(PetJson, - simplifyVector = FALSE) + PetObject <- jsonlite::fromJSON(PetJson) if (!is.null(PetObject$`id`)) { self$`id` <- PetObject$`id` } @@ -171,8 +170,7 @@ Pet <- R6::R6Class( paste('{', jsoncontent, '}', sep = "") }, fromJSONString = function(PetJson) { - PetObject <- jsonlite::fromJSON(PetJson, - simplifyVector = FALSE) + PetObject <- jsonlite::fromJSON(PetJson) self$`id` <- PetObject$`id` self$`category` <- Category$new()$fromJSON(jsonlite::toJSON(PetObject$category, auto_unbox = TRUE, digits = NA)) self$`name` <- PetObject$`name` diff --git a/samples/client/petstore/R/R/tag.R b/samples/client/petstore/R/R/tag.R index 3f28c01fa823..56b89c6b4254 100644 --- a/samples/client/petstore/R/R/tag.R +++ b/samples/client/petstore/R/R/tag.R @@ -52,8 +52,7 @@ Tag <- R6::R6Class( TagObject }, fromJSON = function(TagJson) { - TagObject <- jsonlite::fromJSON(TagJson, - simplifyVector = FALSE) + TagObject <- jsonlite::fromJSON(TagJson) if (!is.null(TagObject$`id`)) { self$`id` <- TagObject$`id` } @@ -83,8 +82,7 @@ Tag <- R6::R6Class( paste('{', jsoncontent, '}', sep = "") }, fromJSONString = function(TagJson) { - TagObject <- jsonlite::fromJSON(TagJson, - simplifyVector = FALSE) + TagObject <- jsonlite::fromJSON(TagJson) self$`id` <- TagObject$`id` self$`name` <- TagObject$`name` self diff --git a/samples/client/petstore/R/R/user.R b/samples/client/petstore/R/R/user.R index b5ac17a386fe..bf88bee40277 100644 --- a/samples/client/petstore/R/R/user.R +++ b/samples/client/petstore/R/R/user.R @@ -118,8 +118,7 @@ User <- R6::R6Class( UserObject }, fromJSON = function(UserJson) { - UserObject <- jsonlite::fromJSON(UserJson, - simplifyVector = FALSE) + UserObject <- jsonlite::fromJSON(UserJson) if (!is.null(UserObject$`id`)) { self$`id` <- UserObject$`id` } @@ -209,8 +208,7 @@ User <- R6::R6Class( paste('{', jsoncontent, '}', sep = "") }, fromJSONString = function(UserJson) { - UserObject <- jsonlite::fromJSON(UserJson, - simplifyVector = FALSE) + UserObject <- jsonlite::fromJSON(UserJson) self$`id` <- UserObject$`id` self$`username` <- UserObject$`username` self$`firstName` <- UserObject$`firstName` From 8852f5bd5c6e30d7d4717b61b69f74d5d81fe4cd Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Tue, 19 May 2020 14:38:20 -0400 Subject: [PATCH 25/26] update api.mustache templates --- modules/openapi-generator/src/main/resources/r/api.mustache | 4 +++- .../src/main/resources/r/api_client.mustache | 4 +++- samples/client/petstore/R/R/api_client.R | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/r/api.mustache b/modules/openapi-generator/src/main/resources/r/api.mustache index 2fd462e13786..51f725da8bd2 100644 --- a/modules/openapi-generator/src/main/resources/r/api.mustache +++ b/modules/openapi-generator/src/main/resources/r/api.mustache @@ -271,7 +271,9 @@ if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { {{#returnType}} {{#isPrimitiveType}} - content <- httr::content(resp, "text", encoding = "UTF-8") + content <- httr::content( + resp, "text", encoding = "UTF-8", simplifyVector = FALSE + ) ApiResponse$new(content,resp) {{/isPrimitiveType}} {{^isPrimitiveType}} diff --git a/modules/openapi-generator/src/main/resources/r/api_client.mustache b/modules/openapi-generator/src/main/resources/r/api_client.mustache index 22fd994ab642..8a403315fa15 100644 --- a/modules/openapi-generator/src/main/resources/r/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/r/api_client.mustache @@ -166,7 +166,9 @@ ApiClient <- R6::R6Class( else if (exists(returnType, pkgEnv) && !(c(returnType) %in% primitiveTypes)) { returnType <- get(returnType, envir = as.environment(pkgEnv)) returnObj <- returnType$new() - returnObj$fromJSON(jsonlite::toJSON(obj, digits = NA)) + returnObj$fromJSON( + jsonlite::toJSON(obj, digits = NA, auto_unbox = TRUE) + ) } # To handle primitive type diff --git a/samples/client/petstore/R/R/api_client.R b/samples/client/petstore/R/R/api_client.R index f6b8544aacd5..fe61ecfbde93 100644 --- a/samples/client/petstore/R/R/api_client.R +++ b/samples/client/petstore/R/R/api_client.R @@ -164,7 +164,9 @@ ApiClient <- R6::R6Class( else if (exists(returnType, pkgEnv) && !(c(returnType) %in% primitiveTypes)) { returnType <- get(returnType, envir = as.environment(pkgEnv)) returnObj <- returnType$new() - returnObj$fromJSON(jsonlite::toJSON(obj, digits = NA)) + returnObj$fromJSON( + jsonlite::toJSON(obj, digits = NA, auto_unbox = TRUE) + ) } # To handle primitive type From 5183ecf875b94a6c0e3da380486084a7533ccc7f Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Tue, 19 May 2020 14:38:38 -0400 Subject: [PATCH 26/26] fix and add tests to package --- .../petstore/R/tests/testthat/test_petstore.R | 90 ++++++++++++++----- 1 file changed, 68 insertions(+), 22 deletions(-) diff --git a/samples/client/petstore/R/tests/testthat/test_petstore.R b/samples/client/petstore/R/tests/testthat/test_petstore.R index 2e24b32f1241..941c30af7e56 100644 --- a/samples/client/petstore/R/tests/testthat/test_petstore.R +++ b/samples/client/petstore/R/tests/testthat/test_petstore.R @@ -1,31 +1,67 @@ context("basic functionality") petApi <- PetApi$new() petId <- 123321 +pet <- Pet$new("name_test", + photoUrls = list("photo_test", "second test"), + category = Category$new(id=450, name="test_cat"), + id = petId, + tags = list( + Tag$new(id=123, name="tag_test"), Tag$new(id=456, name="unknown") + ), + status = "available" +) +result <- petApi$AddPet(pet) + test_that("AddPet", { - pet <- Pet$new("name_test", list("photo_test", "second test"), - petId, Category$new(id=450, name="test_cat"), - list(Tag$new(id=123, name="tag_test"), Tag$new(id=456, name="unknown")), - "available") - #pet <- Pet$new("name_test", - # list("photo_test", "second test"), - # category=Category$new(id=450, name="test_cat"), - # id=petId, - # tags=list(Tag$new(id=123, name="tag_test"), Tag$new(id=456, name="unknown")), - # status="available") - result <-petApi$AddPet(pet) expect_equal(petId, 123321) expect_equal(result, NULL) }) -test_that("Test Pet", { - pet <- Pet$new("name_test", list("photo_test", "second test"), - petId, Category$new(id=450, name="test_cat"), - list(Tag$new(id=123, name="tag_test"), Tag$new(id=456, name="unknown")), - "available") +test_that("Test toJSON toJSON fromJSON fromJSONString", { + pet0 <- Pet$new() + jsonpet <- pet0$toJSON() + pet2 <- pet0$fromJSON( + jsonlite::toJSON(jsonpet, auto_unbox=TRUE) + ) + expect_equal(pet0, pet2) + jsonpet <- pet0$toJSONString() + pet2 <- pet0$fromJSON( + jsonpet + ) + expect_equal(pet0, pet2) + + jsonpet <- pet0$toJSONString() + pet2 <- pet0$fromJSONString( + jsonpet + ) + expect_equal(pet0, pet2) + + pet1 <- Pet$new("name_test", + list("photo_test", "second test"), + category = Category$new(id=450, name="test_cat"), + id = petId, + tags = list( + Tag$new(id=123, name="tag_test"), Tag$new(id=456, name="unknown") + ), + status = "available" + ) + jsonpet <- pet1$toJSON() + pet2 <- pet1$fromJSON( + jsonlite::toJSON(jsonpet, auto_unbox=TRUE) + ) + expect_equal(pet1, pet2) - pet2 <- Pet$new() - #pet2$fromJSON(jsonlite::toJSON(pet$toJSON(), auto_unbox=TRUE)) - #expect_equal(pet, pet2) + jsonpet <- pet1$toJSONString() + pet2 <- pet1$fromJSON( + jsonpet + ) + expect_equal(pet1, pet2) + + jsonpet <- pet1$toJSONString() + pet2 <- pet1$fromJSONString( + jsonpet + ) + expect_equal(pet1, pet2) }) test_that("Test Category", { @@ -33,16 +69,26 @@ test_that("Test Category", { c2 <- Category$new() c2$fromJSON(jsonlite::toJSON(c1$toJSON(), auto_unbox=TRUE)) expect_equal(c1, c2) + c2$fromJSONString(c1$toJSONString()) + expect_equal(c1, c2) }) test_that("GetPetById", { response <- petApi$GetPetById(petId) expect_equal(response$id, petId) expect_equal(response$name, "name_test") - #expect_equal(response$category, Category$new(id=450, name="test_cat")) - expect_equal(response$photoUrls, list("photo_test", "second test")) + expect_equal( + response$photoUrls, + list("photo_test", "second test") + ) expect_equal(response$status, "available") - expect_equal(response$tags, list(Tag$new(id=123, name="tag_test"), Tag$new(id=456, name="unknown"))) + expect_equal(response$category, Category$new(id=450, name="test_cat")) + + expect_equal(pet$tags, response$tags) + expect_equal( + response$tags, + list(Tag$new(id=123, name="tag_test"), Tag$new(id=456, name="unknown")) + ) }) #test_that("GetPetById", {