diff --git a/modules/openapi-generator/src/main/resources/r/api.mustache b/modules/openapi-generator/src/main/resources/r/api.mustache index b3057454cdb..a32d43ba2e6 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 22fd994ab64..8a403315fa1 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/modules/openapi-generator/src/main/resources/r/api_test.mustache b/modules/openapi-generator/src/main/resources/r/api_test.mustache index 6b0bbcf8716..1b7e184d85f 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/modules/openapi-generator/src/main/resources/r/model.mustache b/modules/openapi-generator/src/main/resources/r/model.mustache index bf04a122144..aba9d1b987b 100644 --- a/modules/openapi-generator/src/main/resources/r/model.mustache +++ b/modules/openapi-generator/src/main/resources/r/model.mustache @@ -3,15 +3,21 @@ {{>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 +{{#isEnum}} +{{>modelEnum}} +{{/isEnum}} +{{^isEnum}} #' @export {{classname}} <- R6::R6Class( '{{classname}}', @@ -19,7 +25,9 @@ {{#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}}`)) { @@ -159,6 +167,7 @@ {{/isContainer}} } {{/vars}} + self }, toJSONString = function() { jsoncontent <- c( @@ -241,5 +250,7 @@ } ) ) +{{/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 new file mode 100644 index 00000000000..c648c0365fc --- /dev/null +++ b/modules/openapi-generator/src/main/resources/r/modelEnum.mustache @@ -0,0 +1,48 @@ +#' @export +{{#allowableValues}} +{{classname}} <- R6::R6Class( + "{{classname}}", + public = list( + initialize = function(...) { + local.optional.var <- list(...) + val <- unlist(local.optional.var) + enumvec <- .parse_{{name}}() + + stopifnot(length(val) == 1L) + + if (!val %in% enumvec) + stop("Use one of the valid values: ", + paste0(enumvec, collapse = ", ")) + private$value <- val + }, + toJSON = function() { + jsonlite::toJSON(private$value, auto_unbox = TRUE) + }, + fromJSON = function({{classname}}Json) { + private$value <- jsonlite::fromJSON({{classname}}Json, + simplifyVector = FALSE) + self + }, + toJSONString = function() { + as.character(jsonlite::toJSON(private$value, + auto_unbox = TRUE)) + }, + fromJSONString = function({{classname}}Json) { + private$value <- jsonlite::fromJSON({{classname}}Json, + simplifyVector = FALSE) + self + } + ), + private = list( + value = NULL + ) +) + +# add to utils.R +.parse_{{name}} <- function(vals) { + res <- gsub("^\\[|\\]$", "", + "{{{values}}}" + ) + unlist(strsplit(res, ", ")) +} +{{/allowableValues}} diff --git a/samples/client/petstore/R/R/api_client.R b/samples/client/petstore/R/R/api_client.R index f6b8544aacd..fe61ecfbde9 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 diff --git a/samples/client/petstore/R/R/category.R b/samples/client/petstore/R/R/category.R index 6ff2f1510cc..7c74320d1ac 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) @@ -55,6 +59,7 @@ Category <- R6::R6Class( if (!is.null(CategoryObject$`name`)) { self$`name` <- CategoryObject$`name` } + self }, toJSONString = function() { jsoncontent <- c( @@ -84,3 +89,4 @@ Category <- 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 ddf573164b7..c7cdbb76c2a 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) @@ -69,6 +73,7 @@ ModelApiResponse <- R6::R6Class( if (!is.null(ModelApiResponseObject$`message`)) { self$`message` <- ModelApiResponseObject$`message` } + self }, toJSONString = function() { jsoncontent <- c( @@ -106,3 +111,4 @@ ModelApiResponse <- R6::R6Class( } ) ) + diff --git a/samples/client/petstore/R/R/order.R b/samples/client/petstore/R/R/order.R index a5acac3bfff..3218835cc35 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) @@ -110,6 +114,7 @@ Order <- R6::R6Class( if (!is.null(OrderObject$`complete`)) { self$`complete` <- OrderObject$`complete` } + self }, toJSONString = function() { jsoncontent <- c( @@ -171,3 +176,4 @@ Order <- R6::R6Class( } ) ) + diff --git a/samples/client/petstore/R/R/pet.R b/samples/client/petstore/R/R/pet.R index 760463d67ba..509d16934e1 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) @@ -115,6 +119,7 @@ Pet <- R6::R6Class( if (!is.null(PetObject$`status`)) { self$`status` <- PetObject$`status` } + self }, toJSONString = function() { jsoncontent <- c( @@ -176,3 +181,4 @@ Pet <- R6::R6Class( } ) ) + diff --git a/samples/client/petstore/R/R/tag.R b/samples/client/petstore/R/R/tag.R index 5644807f5c6..56b89c6b425 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) @@ -55,6 +59,7 @@ Tag <- R6::R6Class( if (!is.null(TagObject$`name`)) { self$`name` <- TagObject$`name` } + self }, toJSONString = function() { jsoncontent <- c( @@ -84,3 +89,4 @@ Tag <- R6::R6Class( } ) ) + diff --git a/samples/client/petstore/R/R/user.R b/samples/client/petstore/R/R/user.R index 2afd3de04c6..bf88bee4027 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) @@ -139,6 +143,7 @@ User <- R6::R6Class( if (!is.null(UserObject$`userStatus`)) { self$`userStatus` <- UserObject$`userStatus` } + self }, toJSONString = function() { jsoncontent <- c( @@ -216,3 +221,4 @@ User <- R6::R6Class( } ) ) + diff --git a/samples/client/petstore/R/tests/testthat/test_order.R b/samples/client/petstore/R/tests/testthat/test_order.R index 5fb144f9372..33b87520254 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 8d3ce54a55d..ac3e4f31dd1 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 021f6228af9..7fbdd1a70de 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_petstore.R b/samples/client/petstore/R/tests/testthat/test_petstore.R index 2e24b32f124..941c30af7e5 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) - pet2 <- Pet$new() - #pet2$fromJSON(jsonlite::toJSON(pet$toJSON(), auto_unbox=TRUE)) - #expect_equal(pet, 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) + + 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", { 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 e1290358b43..1ebb3f82a63 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 401196a90d7..9929623b42f 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 283c7c7e964..8b8c3ba3847 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 d67bd9cf238..00000000000 --- a/samples/client/petstore/R/testthat.R +++ /dev/null @@ -1,4 +0,0 @@ -library(testthat) -library(petstore) - -test_check("petstore")