forked from loafle/openapi-generator-original
[R] Add petstore integration tests to CI (#2354)
* add r petstore test * run test in node 1 * fix r bash test * fix typo * fix permission error * fix r installation error * use diff r repo * install latest r * install curl * use sudo for apt-get * add no manual * add sudo install * better caching * export env * update lib location * create lib dir * update r lib dir
This commit is contained in:
parent
b0aac250c6
commit
3ba6d8226e
@ -20,12 +20,23 @@ elif [ "$NODE_INDEX" = "2" ]; then
|
|||||||
java -version
|
java -version
|
||||||
./bin/utils/ensure-up-to-date
|
./bin/utils/ensure-up-to-date
|
||||||
fi
|
fi
|
||||||
elif [ "$NODE_INDEX" = "3" ]; then
|
#elif [ "$NODE_INDEX" = "3" ]; then
|
||||||
echo "Running node $NODE_INDEX to test haskell"
|
echo "Running node $NODE_INDEX to test haskell"
|
||||||
# install haskell
|
# install haskell
|
||||||
url -sSL https://get.haskellstack.org/ | sh
|
curl -sSL https://get.haskellstack.org/ | sh
|
||||||
stack upgrade
|
stack upgrade
|
||||||
stack --version:w
|
stack --version
|
||||||
|
# install r
|
||||||
|
sudo sh -c 'echo "deb http://cran.rstudio.com/bin/linux/ubuntu trusty/" >> /etc/apt/sources.list'
|
||||||
|
gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9
|
||||||
|
gpg -a --export E084DAB9 | sudo apt-key add -
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get -y install r-base
|
||||||
|
R --version
|
||||||
|
# install curl
|
||||||
|
sudo apt-get -y build-dep libcurl4-gnutls-dev
|
||||||
|
sudo apt-get -y install libcurl4-gnutls-dev
|
||||||
|
# run integration tests
|
||||||
mvn --quiet verify -Psamples.misc
|
mvn --quiet verify -Psamples.misc
|
||||||
else
|
else
|
||||||
echo "Running node $NODE_INDEX to test 'samples.circleci.jdk7' defined in pom.xml ..."
|
echo "Running node $NODE_INDEX to test 'samples.circleci.jdk7' defined in pom.xml ..."
|
||||||
|
@ -84,6 +84,8 @@ jobs:
|
|||||||
- ~/.cache/bower
|
- ~/.cache/bower
|
||||||
- ".git"
|
- ".git"
|
||||||
- ~/.stack
|
- ~/.stack
|
||||||
|
- /home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/haskell-http-client/.stack-work
|
||||||
|
- ~/R
|
||||||
# Teardown
|
# Teardown
|
||||||
# If you break your build into multiple jobs with workflows, you will probably want to do the parts of this that are relevant in each
|
# If you break your build into multiple jobs with workflows, you will probably want to do the parts of this that are relevant in each
|
||||||
# Save test results
|
# Save test results
|
||||||
|
1
pom.xml
1
pom.xml
@ -1250,6 +1250,7 @@
|
|||||||
</activation>
|
</activation>
|
||||||
<modules>
|
<modules>
|
||||||
<!-- clients -->
|
<!-- clients -->
|
||||||
|
<module>samples/client/petstore/R</module>
|
||||||
<module>samples/client/petstore/haskell-http-client</module>
|
<module>samples/client/petstore/haskell-http-client</module>
|
||||||
<!-- servers -->
|
<!-- servers -->
|
||||||
<module>samples/server/petstore/haskell-servant</module>
|
<module>samples/server/petstore/haskell-servant</module>
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
Package: petstore
|
|
||||||
Title: R Package Client for Swagger Petstore
|
|
||||||
Version: 1.0.0
|
|
||||||
Authors@R: person("Swagger Codegen community", email = "apiteam@swagger.io", role = c("aut", "cre"))
|
|
||||||
Description: This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
|
|
||||||
Depends: R (>= 3.3.3)
|
|
||||||
Encoding: UTF-8
|
|
||||||
License: Unlicense
|
|
||||||
LazyData: true
|
|
||||||
Suggests: testthat
|
|
||||||
Imports: jsonlite, httr, R6
|
|
||||||
RoxygenNote: 6.0.1.9000
|
|
@ -1,11 +0,0 @@
|
|||||||
# Generated by roxygen2: do not edit by hand
|
|
||||||
|
|
||||||
export(ApiResponse)
|
|
||||||
export(Category)
|
|
||||||
export(Element)
|
|
||||||
export(Order)
|
|
||||||
export(Pet)
|
|
||||||
export(PetStoreClient)
|
|
||||||
export(Response)
|
|
||||||
export(Tag)
|
|
||||||
export(User)
|
|
@ -1,93 +0,0 @@
|
|||||||
# Swagger Petstore
|
|
||||||
#
|
|
||||||
# This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
|
|
||||||
#
|
|
||||||
# OpenAPI spec version: 1.0.0
|
|
||||||
# Contact: apiteam@swagger.io
|
|
||||||
# Generated by: https://github.com/swagger-api/swagger-codegen.git
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#' ApiResponse Class
|
|
||||||
#' @export
|
|
||||||
ApiResponse <- R6::R6Class(
|
|
||||||
'ApiResponse',
|
|
||||||
public = list(
|
|
||||||
`code` = NULL,
|
|
||||||
`type` = NULL,
|
|
||||||
`message` = NULL,
|
|
||||||
initialize = function(`code`, `type`, `message`){
|
|
||||||
if (!missing(`code`)) {
|
|
||||||
stopifnot(is.numeric(`code`), length(`code`) == 1)
|
|
||||||
self$`code` <- `code`
|
|
||||||
}
|
|
||||||
if (!missing(`type`)) {
|
|
||||||
stopifnot(is.character(`type`), length(`type`) == 1)
|
|
||||||
self$`type` <- `type`
|
|
||||||
}
|
|
||||||
if (!missing(`message`)) {
|
|
||||||
stopifnot(is.character(`message`), length(`message`) == 1)
|
|
||||||
self$`message` <- `message`
|
|
||||||
}
|
|
||||||
},
|
|
||||||
toJSON = function() {
|
|
||||||
sprintf(
|
|
||||||
'{
|
|
||||||
"code": "%s",
|
|
||||||
"type": "%s",
|
|
||||||
"message": "%s"
|
|
||||||
}',
|
|
||||||
self$`code`,
|
|
||||||
self$`type`,
|
|
||||||
self$`message`
|
|
||||||
)
|
|
||||||
},
|
|
||||||
fromJSON = function(ApiResponseJson) {
|
|
||||||
ApiResponseObject <- jsonlite::fromJSON(ApiResponseJson)
|
|
||||||
self$`code` <- ApiResponseObject$`code`
|
|
||||||
self$`type` <- ApiResponseObject$`type`
|
|
||||||
self$`message` <- ApiResponseObject$`message`
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
#' Element Class
|
|
||||||
#'
|
|
||||||
#' Element Class
|
|
||||||
#' @export
|
|
||||||
Element <- R6::R6Class(
|
|
||||||
'Element',
|
|
||||||
public = list(
|
|
||||||
id = NULL,
|
|
||||||
name = NULL,
|
|
||||||
initialize = function(id,name){
|
|
||||||
if (!missing(id)) {
|
|
||||||
stopifnot(is.numeric(id), length(id) == 1)
|
|
||||||
self$id <- id
|
|
||||||
}
|
|
||||||
if (!missing(name)) {
|
|
||||||
stopifnot(is.character(name), length(name) == 1)
|
|
||||||
self$name <- name
|
|
||||||
}
|
|
||||||
},
|
|
||||||
toJSON = function() {
|
|
||||||
sprintf('{"id":%d,"name":"%s"}', self$id, self$name)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
#' Response Class
|
|
||||||
#'
|
|
||||||
#' Response Class
|
|
||||||
#' @export
|
|
||||||
Response <- R6::R6Class(
|
|
||||||
'Response',
|
|
||||||
public = list(
|
|
||||||
content = NULL,
|
|
||||||
response = NULL,
|
|
||||||
initialize = function(content, response){
|
|
||||||
self$content <- content
|
|
||||||
self$response <- response
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
@ -1,85 +0,0 @@
|
|||||||
# Swagger Petstore
|
|
||||||
#
|
|
||||||
# This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
|
|
||||||
#
|
|
||||||
# OpenAPI spec version: 1.0.0
|
|
||||||
# Contact: apiteam@swagger.io
|
|
||||||
# Generated by: https://github.com/swagger-api/swagger-codegen.git
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#' Category Class
|
|
||||||
#' @export
|
|
||||||
Category <- R6::R6Class(
|
|
||||||
'Category',
|
|
||||||
public = list(
|
|
||||||
`id` = NULL,
|
|
||||||
`name` = NULL,
|
|
||||||
initialize = function(`id`, `name`){
|
|
||||||
if (!missing(`id`)) {
|
|
||||||
stopifnot(is.numeric(`id`), length(`id`) == 1)
|
|
||||||
self$`id` <- `id`
|
|
||||||
}
|
|
||||||
if (!missing(`name`)) {
|
|
||||||
stopifnot(is.character(`name`), length(`name`) == 1)
|
|
||||||
self$`name` <- `name`
|
|
||||||
}
|
|
||||||
},
|
|
||||||
toJSON = function() {
|
|
||||||
sprintf(
|
|
||||||
'{
|
|
||||||
"id": %d,
|
|
||||||
"name": "%s"
|
|
||||||
}',
|
|
||||||
self$`id`,
|
|
||||||
self$`name`
|
|
||||||
)
|
|
||||||
},
|
|
||||||
fromJSON = function(CategoryJson) {
|
|
||||||
CategoryObject <- jsonlite::fromJSON(CategoryJson)
|
|
||||||
self$`id` <- CategoryObject$`id`
|
|
||||||
self$`name` <- CategoryObject$`name`
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
#' Element Class
|
|
||||||
#'
|
|
||||||
#' Element Class
|
|
||||||
#' @export
|
|
||||||
Element <- R6::R6Class(
|
|
||||||
'Element',
|
|
||||||
public = list(
|
|
||||||
id = NULL,
|
|
||||||
name = NULL,
|
|
||||||
initialize = function(id,name){
|
|
||||||
if (!missing(id)) {
|
|
||||||
stopifnot(is.numeric(id), length(id) == 1)
|
|
||||||
self$id <- id
|
|
||||||
}
|
|
||||||
if (!missing(name)) {
|
|
||||||
stopifnot(is.character(name), length(name) == 1)
|
|
||||||
self$name <- name
|
|
||||||
}
|
|
||||||
},
|
|
||||||
toJSON = function() {
|
|
||||||
sprintf('{"id":%d,"name":"%s"}', self$id, self$name)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
#' Response Class
|
|
||||||
#'
|
|
||||||
#' Response Class
|
|
||||||
#' @export
|
|
||||||
Response <- R6::R6Class(
|
|
||||||
'Response',
|
|
||||||
public = list(
|
|
||||||
content = NULL,
|
|
||||||
response = NULL,
|
|
||||||
initialize = function(content, response){
|
|
||||||
self$content <- content
|
|
||||||
self$response <- response
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
@ -1,116 +0,0 @@
|
|||||||
# Swagger Petstore
|
|
||||||
#
|
|
||||||
# This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
|
|
||||||
#
|
|
||||||
# OpenAPI spec version: 1.0.0
|
|
||||||
# Contact: apiteam@swagger.io
|
|
||||||
# Generated by: https://github.com/swagger-api/swagger-codegen.git
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#' Order Class
|
|
||||||
#' @export
|
|
||||||
Order <- R6::R6Class(
|
|
||||||
'Order',
|
|
||||||
public = list(
|
|
||||||
`id` = NULL,
|
|
||||||
`petId` = NULL,
|
|
||||||
`quantity` = NULL,
|
|
||||||
`shipDate` = NULL,
|
|
||||||
`status` = NULL,
|
|
||||||
`complete` = NULL,
|
|
||||||
initialize = function(`id`, `petId`, `quantity`, `shipDate`, `status`, `complete`){
|
|
||||||
if (!missing(`id`)) {
|
|
||||||
stopifnot(is.numeric(`id`), length(`id`) == 1)
|
|
||||||
self$`id` <- `id`
|
|
||||||
}
|
|
||||||
if (!missing(`petId`)) {
|
|
||||||
stopifnot(is.numeric(`petId`), length(`petId`) == 1)
|
|
||||||
self$`petId` <- `petId`
|
|
||||||
}
|
|
||||||
if (!missing(`quantity`)) {
|
|
||||||
stopifnot(is.numeric(`quantity`), length(`quantity`) == 1)
|
|
||||||
self$`quantity` <- `quantity`
|
|
||||||
}
|
|
||||||
if (!missing(`shipDate`)) {
|
|
||||||
stopifnot(is.character(`shipDate`), length(`shipDate`) == 1)
|
|
||||||
self$`shipDate` <- `shipDate`
|
|
||||||
}
|
|
||||||
if (!missing(`status`)) {
|
|
||||||
stopifnot(is.character(`status`), length(`status`) == 1)
|
|
||||||
self$`status` <- `status`
|
|
||||||
}
|
|
||||||
if (!missing(`complete`)) {
|
|
||||||
self$`complete` <- `complete`
|
|
||||||
}
|
|
||||||
},
|
|
||||||
toJSON = function() {
|
|
||||||
sprintf(
|
|
||||||
'{
|
|
||||||
"id": %d,
|
|
||||||
"petId": %d,
|
|
||||||
"quantity": "%s",
|
|
||||||
"shipDate": "%s",
|
|
||||||
"status": "%s",
|
|
||||||
"complete": "%s"
|
|
||||||
}',
|
|
||||||
self$`id`,
|
|
||||||
self$`petId`,
|
|
||||||
self$`quantity`,
|
|
||||||
self$`shipDate`,
|
|
||||||
self$`status`,
|
|
||||||
self$`complete`
|
|
||||||
)
|
|
||||||
},
|
|
||||||
fromJSON = function(OrderJson) {
|
|
||||||
OrderObject <- jsonlite::fromJSON(OrderJson)
|
|
||||||
self$`id` <- OrderObject$`id`
|
|
||||||
self$`petId` <- OrderObject$`petId`
|
|
||||||
self$`quantity` <- OrderObject$`quantity`
|
|
||||||
self$`shipDate` <- OrderObject$`shipDate`
|
|
||||||
self$`status` <- OrderObject$`status`
|
|
||||||
self$`complete` <- OrderObject$`complete`
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
#' Element Class
|
|
||||||
#'
|
|
||||||
#' Element Class
|
|
||||||
#' @export
|
|
||||||
Element <- R6::R6Class(
|
|
||||||
'Element',
|
|
||||||
public = list(
|
|
||||||
id = NULL,
|
|
||||||
name = NULL,
|
|
||||||
initialize = function(id,name){
|
|
||||||
if (!missing(id)) {
|
|
||||||
stopifnot(is.numeric(id), length(id) == 1)
|
|
||||||
self$id <- id
|
|
||||||
}
|
|
||||||
if (!missing(name)) {
|
|
||||||
stopifnot(is.character(name), length(name) == 1)
|
|
||||||
self$name <- name
|
|
||||||
}
|
|
||||||
},
|
|
||||||
toJSON = function() {
|
|
||||||
sprintf('{"id":%d,"name":"%s"}', self$id, self$name)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
#' Response Class
|
|
||||||
#'
|
|
||||||
#' Response Class
|
|
||||||
#' @export
|
|
||||||
Response <- R6::R6Class(
|
|
||||||
'Response',
|
|
||||||
public = list(
|
|
||||||
content = NULL,
|
|
||||||
response = NULL,
|
|
||||||
initialize = function(content, response){
|
|
||||||
self$content <- content
|
|
||||||
self$response <- response
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
@ -1,154 +0,0 @@
|
|||||||
# Swagger Petstore
|
|
||||||
#
|
|
||||||
# This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
|
|
||||||
#
|
|
||||||
# OpenAPI spec version: 1.0.0
|
|
||||||
# Contact: apiteam@swagger.io
|
|
||||||
# Generated by: https://github.com/swagger-api/swagger-codegen.git
|
|
||||||
|
|
||||||
PetApi <- R6::R6Class(
|
|
||||||
'PetApi',
|
|
||||||
public = list(
|
|
||||||
userAgent = "Swagger-Codegen/1.0.0/r",
|
|
||||||
basePath = "http://petstore.swagger.io/v2",
|
|
||||||
initialize = function(basePath){
|
|
||||||
if (!missing(basePath)) {
|
|
||||||
stopifnot(is.character(basePath), length(basePath) == 1)
|
|
||||||
self$basePath <- basePath
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
add_pet = function(body){
|
|
||||||
resp <- httr::POST(paste0(self$basePath),
|
|
||||||
httr::add_headers("User-Agent" = self$userAgent, "accept" = "application/json", "content-type" = "application/xml")
|
|
||||||
,body = body$toJSON()
|
|
||||||
)
|
|
||||||
|
|
||||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
|
||||||
# void response, no need to return anything
|
|
||||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
|
||||||
Response$new("API client error", resp)
|
|
||||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
|
||||||
Response$new("API server error", resp)
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
delete_pet = function(pet_id, api_key){
|
|
||||||
resp <- httr::DELETE(paste0(self$basePath, pet_id),
|
|
||||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml", "api_key" = api_key)
|
|
||||||
)
|
|
||||||
|
|
||||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
|
||||||
# void response, no need to return anything
|
|
||||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
|
||||||
Response$new("API client error", resp)
|
|
||||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
|
||||||
Response$new("API server error", resp)
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
find_pets_by_status = function(status){
|
|
||||||
resp <- httr::GET(paste0(self$basePath),
|
|
||||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml")
|
|
||||||
,query = list(
|
|
||||||
"status" = status
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
|
||||||
result <- Pet$new()$fromJSON(httr::content(resp, "text", encoding = "UTF-8"), simplifyVector = FALSE)
|
|
||||||
Response$new(result, resp)
|
|
||||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
|
||||||
Response$new("API client error", resp)
|
|
||||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
|
||||||
Response$new("API server error", resp)
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
find_pets_by_tags = function(tags){
|
|
||||||
resp <- httr::GET(paste0(self$basePath),
|
|
||||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml")
|
|
||||||
,query = list(
|
|
||||||
"tags" = tags
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
|
||||||
result <- Pet$new()$fromJSON(httr::content(resp, "text", encoding = "UTF-8"), simplifyVector = FALSE)
|
|
||||||
Response$new(result, resp)
|
|
||||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
|
||||||
Response$new("API client error", resp)
|
|
||||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
|
||||||
Response$new("API server error", resp)
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
get_pet_by_id = function(pet_id){
|
|
||||||
resp <- httr::GET(paste0(self$basePath, pet_id),
|
|
||||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml")
|
|
||||||
)
|
|
||||||
|
|
||||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
|
||||||
result <- Pet$new()$fromJSON(httr::content(resp, "text", encoding = "UTF-8"), simplifyVector = FALSE)
|
|
||||||
Response$new(result, resp)
|
|
||||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
|
||||||
Response$new("API client error", resp)
|
|
||||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
|
||||||
Response$new("API server error", resp)
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
update_pet = function(body){
|
|
||||||
resp <- httr::PUT(paste0(self$basePath),
|
|
||||||
httr::add_headers("User-Agent" = self$userAgent, "accept" = "application/json", "content-type" = "application/xml")
|
|
||||||
,body = body$toJSON()
|
|
||||||
)
|
|
||||||
|
|
||||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
|
||||||
# void response, no need to return anything
|
|
||||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
|
||||||
Response$new("API client error", resp)
|
|
||||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
|
||||||
Response$new("API server error", resp)
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
update_pet_with_form = function(pet_id, name, status){
|
|
||||||
resp <- httr::POST(paste0(self$basePath, pet_id),
|
|
||||||
httr::add_headers("User-Agent" = self$userAgent, "accept" = "application/x-www-form-urlencoded", "content-type" = "application/xml")
|
|
||||||
,body = list(
|
|
||||||
"name" = name,
|
|
||||||
"status" = status
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
|
||||||
# void response, no need to return anything
|
|
||||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
|
||||||
Response$new("API client error", resp)
|
|
||||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
|
||||||
Response$new("API server error", resp)
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
upload_file = function(pet_id, additional_metadata, file){
|
|
||||||
resp <- httr::POST(paste0(self$basePath, pet_id),
|
|
||||||
httr::add_headers("User-Agent" = self$userAgent, "accept" = "multipart/form-data", "content-type" = "application/json")
|
|
||||||
,body = list(
|
|
||||||
"additionalMetadata" = additional_metadata,
|
|
||||||
"file" = httr::upload_file(file)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
|
||||||
result <- ApiResponse$new()$fromJSON(httr::content(resp, "text", encoding = "UTF-8"), simplifyVector = FALSE)
|
|
||||||
Response$new(result, resp)
|
|
||||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
|
||||||
Response$new("API client error", resp)
|
|
||||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
|
||||||
Response$new("API server error", resp)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
@ -1,82 +0,0 @@
|
|||||||
# Swagger Petstore
|
|
||||||
#
|
|
||||||
# This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
|
|
||||||
#
|
|
||||||
# OpenAPI spec version: 1.0.0
|
|
||||||
# Contact: apiteam@swagger.io
|
|
||||||
# Generated by: https://github.com/swagger-api/swagger-codegen.git
|
|
||||||
|
|
||||||
StoreApi <- R6::R6Class(
|
|
||||||
'StoreApi',
|
|
||||||
public = list(
|
|
||||||
userAgent = "Swagger-Codegen/1.0.0/r",
|
|
||||||
basePath = "http://petstore.swagger.io/v2",
|
|
||||||
initialize = function(basePath){
|
|
||||||
if (!missing(basePath)) {
|
|
||||||
stopifnot(is.character(basePath), length(basePath) == 1)
|
|
||||||
self$basePath <- basePath
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
delete_order = function(order_id){
|
|
||||||
resp <- httr::DELETE(paste0(self$basePath, order_id),
|
|
||||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml")
|
|
||||||
)
|
|
||||||
|
|
||||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
|
||||||
# void response, no need to return anything
|
|
||||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
|
||||||
Response$new("API client error", resp)
|
|
||||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
|
||||||
Response$new("API server error", resp)
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
get_inventory = function(){
|
|
||||||
resp <- httr::GET(paste0(self$basePath),
|
|
||||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/json")
|
|
||||||
)
|
|
||||||
|
|
||||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
|
||||||
result <- Integer$new()$fromJSON(httr::content(resp, "text", encoding = "UTF-8"), simplifyVector = FALSE)
|
|
||||||
Response$new(result, resp)
|
|
||||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
|
||||||
Response$new("API client error", resp)
|
|
||||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
|
||||||
Response$new("API server error", resp)
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
get_order_by_id = function(order_id){
|
|
||||||
resp <- httr::GET(paste0(self$basePath, order_id),
|
|
||||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml")
|
|
||||||
)
|
|
||||||
|
|
||||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
|
||||||
result <- Order$new()$fromJSON(httr::content(resp, "text", encoding = "UTF-8"), simplifyVector = FALSE)
|
|
||||||
Response$new(result, resp)
|
|
||||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
|
||||||
Response$new("API client error", resp)
|
|
||||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
|
||||||
Response$new("API server error", resp)
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
place_order = function(body){
|
|
||||||
resp <- httr::POST(paste0(self$basePath),
|
|
||||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml")
|
|
||||||
,body = body$toJSON()
|
|
||||||
)
|
|
||||||
|
|
||||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
|
||||||
result <- Order$new()$fromJSON(httr::content(resp, "text", encoding = "UTF-8"), simplifyVector = FALSE)
|
|
||||||
Response$new(result, resp)
|
|
||||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
|
||||||
Response$new("API client error", resp)
|
|
||||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
|
||||||
Response$new("API server error", resp)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
@ -1,85 +0,0 @@
|
|||||||
# Swagger Petstore
|
|
||||||
#
|
|
||||||
# This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
|
|
||||||
#
|
|
||||||
# OpenAPI spec version: 1.0.0
|
|
||||||
# Contact: apiteam@swagger.io
|
|
||||||
# Generated by: https://github.com/swagger-api/swagger-codegen.git
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#' Tag Class
|
|
||||||
#' @export
|
|
||||||
Tag <- R6::R6Class(
|
|
||||||
'Tag',
|
|
||||||
public = list(
|
|
||||||
`id` = NULL,
|
|
||||||
`name` = NULL,
|
|
||||||
initialize = function(`id`, `name`){
|
|
||||||
if (!missing(`id`)) {
|
|
||||||
stopifnot(is.numeric(`id`), length(`id`) == 1)
|
|
||||||
self$`id` <- `id`
|
|
||||||
}
|
|
||||||
if (!missing(`name`)) {
|
|
||||||
stopifnot(is.character(`name`), length(`name`) == 1)
|
|
||||||
self$`name` <- `name`
|
|
||||||
}
|
|
||||||
},
|
|
||||||
toJSON = function() {
|
|
||||||
sprintf(
|
|
||||||
'{
|
|
||||||
"id": %d,
|
|
||||||
"name": "%s"
|
|
||||||
}',
|
|
||||||
self$`id`,
|
|
||||||
self$`name`
|
|
||||||
)
|
|
||||||
},
|
|
||||||
fromJSON = function(TagJson) {
|
|
||||||
TagObject <- jsonlite::fromJSON(TagJson)
|
|
||||||
self$`id` <- TagObject$`id`
|
|
||||||
self$`name` <- TagObject$`name`
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
#' Element Class
|
|
||||||
#'
|
|
||||||
#' Element Class
|
|
||||||
#' @export
|
|
||||||
Element <- R6::R6Class(
|
|
||||||
'Element',
|
|
||||||
public = list(
|
|
||||||
id = NULL,
|
|
||||||
name = NULL,
|
|
||||||
initialize = function(id,name){
|
|
||||||
if (!missing(id)) {
|
|
||||||
stopifnot(is.numeric(id), length(id) == 1)
|
|
||||||
self$id <- id
|
|
||||||
}
|
|
||||||
if (!missing(name)) {
|
|
||||||
stopifnot(is.character(name), length(name) == 1)
|
|
||||||
self$name <- name
|
|
||||||
}
|
|
||||||
},
|
|
||||||
toJSON = function() {
|
|
||||||
sprintf('{"id":%d,"name":"%s"}', self$id, self$name)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
#' Response Class
|
|
||||||
#'
|
|
||||||
#' Response Class
|
|
||||||
#' @export
|
|
||||||
Response <- R6::R6Class(
|
|
||||||
'Response',
|
|
||||||
public = list(
|
|
||||||
content = NULL,
|
|
||||||
response = NULL,
|
|
||||||
initialize = function(content, response){
|
|
||||||
self$content <- content
|
|
||||||
self$response <- response
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
@ -1,133 +0,0 @@
|
|||||||
# Swagger Petstore
|
|
||||||
#
|
|
||||||
# This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
|
|
||||||
#
|
|
||||||
# OpenAPI spec version: 1.0.0
|
|
||||||
# Contact: apiteam@swagger.io
|
|
||||||
# Generated by: https://github.com/swagger-api/swagger-codegen.git
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#' User Class
|
|
||||||
#' @export
|
|
||||||
User <- R6::R6Class(
|
|
||||||
'User',
|
|
||||||
public = list(
|
|
||||||
`id` = NULL,
|
|
||||||
`username` = NULL,
|
|
||||||
`firstName` = NULL,
|
|
||||||
`lastName` = NULL,
|
|
||||||
`email` = NULL,
|
|
||||||
`password` = NULL,
|
|
||||||
`phone` = NULL,
|
|
||||||
`userStatus` = NULL,
|
|
||||||
initialize = function(`id`, `username`, `firstName`, `lastName`, `email`, `password`, `phone`, `userStatus`){
|
|
||||||
if (!missing(`id`)) {
|
|
||||||
stopifnot(is.numeric(`id`), length(`id`) == 1)
|
|
||||||
self$`id` <- `id`
|
|
||||||
}
|
|
||||||
if (!missing(`username`)) {
|
|
||||||
stopifnot(is.character(`username`), length(`username`) == 1)
|
|
||||||
self$`username` <- `username`
|
|
||||||
}
|
|
||||||
if (!missing(`firstName`)) {
|
|
||||||
stopifnot(is.character(`firstName`), length(`firstName`) == 1)
|
|
||||||
self$`firstName` <- `firstName`
|
|
||||||
}
|
|
||||||
if (!missing(`lastName`)) {
|
|
||||||
stopifnot(is.character(`lastName`), length(`lastName`) == 1)
|
|
||||||
self$`lastName` <- `lastName`
|
|
||||||
}
|
|
||||||
if (!missing(`email`)) {
|
|
||||||
stopifnot(is.character(`email`), length(`email`) == 1)
|
|
||||||
self$`email` <- `email`
|
|
||||||
}
|
|
||||||
if (!missing(`password`)) {
|
|
||||||
stopifnot(is.character(`password`), length(`password`) == 1)
|
|
||||||
self$`password` <- `password`
|
|
||||||
}
|
|
||||||
if (!missing(`phone`)) {
|
|
||||||
stopifnot(is.character(`phone`), length(`phone`) == 1)
|
|
||||||
self$`phone` <- `phone`
|
|
||||||
}
|
|
||||||
if (!missing(`userStatus`)) {
|
|
||||||
stopifnot(is.numeric(`userStatus`), length(`userStatus`) == 1)
|
|
||||||
self$`userStatus` <- `userStatus`
|
|
||||||
}
|
|
||||||
},
|
|
||||||
toJSON = function() {
|
|
||||||
sprintf(
|
|
||||||
'{
|
|
||||||
"id": %d,
|
|
||||||
"username": "%s",
|
|
||||||
"firstName": "%s",
|
|
||||||
"lastName": "%s",
|
|
||||||
"email": "%s",
|
|
||||||
"password": "%s",
|
|
||||||
"phone": "%s",
|
|
||||||
"userStatus": "%s"
|
|
||||||
}',
|
|
||||||
self$`id`,
|
|
||||||
self$`username`,
|
|
||||||
self$`firstName`,
|
|
||||||
self$`lastName`,
|
|
||||||
self$`email`,
|
|
||||||
self$`password`,
|
|
||||||
self$`phone`,
|
|
||||||
self$`userStatus`
|
|
||||||
)
|
|
||||||
},
|
|
||||||
fromJSON = function(UserJson) {
|
|
||||||
UserObject <- jsonlite::fromJSON(UserJson)
|
|
||||||
self$`id` <- UserObject$`id`
|
|
||||||
self$`username` <- UserObject$`username`
|
|
||||||
self$`firstName` <- UserObject$`firstName`
|
|
||||||
self$`lastName` <- UserObject$`lastName`
|
|
||||||
self$`email` <- UserObject$`email`
|
|
||||||
self$`password` <- UserObject$`password`
|
|
||||||
self$`phone` <- UserObject$`phone`
|
|
||||||
self$`userStatus` <- UserObject$`userStatus`
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
#' Element Class
|
|
||||||
#'
|
|
||||||
#' Element Class
|
|
||||||
#' @export
|
|
||||||
Element <- R6::R6Class(
|
|
||||||
'Element',
|
|
||||||
public = list(
|
|
||||||
id = NULL,
|
|
||||||
name = NULL,
|
|
||||||
initialize = function(id,name){
|
|
||||||
if (!missing(id)) {
|
|
||||||
stopifnot(is.numeric(id), length(id) == 1)
|
|
||||||
self$id <- id
|
|
||||||
}
|
|
||||||
if (!missing(name)) {
|
|
||||||
stopifnot(is.character(name), length(name) == 1)
|
|
||||||
self$name <- name
|
|
||||||
}
|
|
||||||
},
|
|
||||||
toJSON = function() {
|
|
||||||
sprintf('{"id":%d,"name":"%s"}', self$id, self$name)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
#' Response Class
|
|
||||||
#'
|
|
||||||
#' Response Class
|
|
||||||
#' @export
|
|
||||||
Response <- R6::R6Class(
|
|
||||||
'Response',
|
|
||||||
public = list(
|
|
||||||
content = NULL,
|
|
||||||
response = NULL,
|
|
||||||
initialize = function(content, response){
|
|
||||||
self$content <- content
|
|
||||||
self$response <- response
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
@ -1,144 +0,0 @@
|
|||||||
# Swagger Petstore
|
|
||||||
#
|
|
||||||
# This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
|
|
||||||
#
|
|
||||||
# OpenAPI spec version: 1.0.0
|
|
||||||
# Contact: apiteam@swagger.io
|
|
||||||
# Generated by: https://github.com/swagger-api/swagger-codegen.git
|
|
||||||
|
|
||||||
UserApi <- R6::R6Class(
|
|
||||||
'UserApi',
|
|
||||||
public = list(
|
|
||||||
userAgent = "Swagger-Codegen/1.0.0/r",
|
|
||||||
basePath = "http://petstore.swagger.io/v2",
|
|
||||||
initialize = function(basePath){
|
|
||||||
if (!missing(basePath)) {
|
|
||||||
stopifnot(is.character(basePath), length(basePath) == 1)
|
|
||||||
self$basePath <- basePath
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
create_user = function(body){
|
|
||||||
resp <- httr::POST(paste0(self$basePath),
|
|
||||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml")
|
|
||||||
,body = body$toJSON()
|
|
||||||
)
|
|
||||||
|
|
||||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
|
||||||
# void response, no need to return anything
|
|
||||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
|
||||||
Response$new("API client error", resp)
|
|
||||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
|
||||||
Response$new("API server error", resp)
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
create_users_with_array_input = function(body){
|
|
||||||
resp <- httr::POST(paste0(self$basePath),
|
|
||||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml")
|
|
||||||
,body = body$toJSON()
|
|
||||||
)
|
|
||||||
|
|
||||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
|
||||||
# void response, no need to return anything
|
|
||||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
|
||||||
Response$new("API client error", resp)
|
|
||||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
|
||||||
Response$new("API server error", resp)
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
create_users_with_list_input = function(body){
|
|
||||||
resp <- httr::POST(paste0(self$basePath),
|
|
||||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml")
|
|
||||||
,body = body$toJSON()
|
|
||||||
)
|
|
||||||
|
|
||||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
|
||||||
# void response, no need to return anything
|
|
||||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
|
||||||
Response$new("API client error", resp)
|
|
||||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
|
||||||
Response$new("API server error", resp)
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
delete_user = function(username){
|
|
||||||
resp <- httr::DELETE(paste0(self$basePath, username),
|
|
||||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml")
|
|
||||||
)
|
|
||||||
|
|
||||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
|
||||||
# void response, no need to return anything
|
|
||||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
|
||||||
Response$new("API client error", resp)
|
|
||||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
|
||||||
Response$new("API server error", resp)
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
get_user_by_name = function(username){
|
|
||||||
resp <- httr::GET(paste0(self$basePath, username),
|
|
||||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml")
|
|
||||||
)
|
|
||||||
|
|
||||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
|
||||||
result <- User$new()$fromJSON(httr::content(resp, "text", encoding = "UTF-8"), simplifyVector = FALSE)
|
|
||||||
Response$new(result, resp)
|
|
||||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
|
||||||
Response$new("API client error", resp)
|
|
||||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
|
||||||
Response$new("API server error", resp)
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
login_user = function(username, password){
|
|
||||||
resp <- httr::GET(paste0(self$basePath),
|
|
||||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml")
|
|
||||||
,query = list(
|
|
||||||
"username" = username,
|
|
||||||
"password" = password
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
|
||||||
result <- Character$new()$fromJSON(httr::content(resp, "text", encoding = "UTF-8"), simplifyVector = FALSE)
|
|
||||||
Response$new(result, resp)
|
|
||||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
|
||||||
Response$new("API client error", resp)
|
|
||||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
|
||||||
Response$new("API server error", resp)
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
logout_user = function(){
|
|
||||||
resp <- httr::GET(paste0(self$basePath),
|
|
||||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml")
|
|
||||||
)
|
|
||||||
|
|
||||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
|
||||||
# void response, no need to return anything
|
|
||||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
|
||||||
Response$new("API client error", resp)
|
|
||||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
|
||||||
Response$new("API server error", resp)
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
update_user = function(username, body){
|
|
||||||
resp <- httr::PUT(paste0(self$basePath, username),
|
|
||||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml")
|
|
||||||
,body = body$toJSON()
|
|
||||||
)
|
|
||||||
|
|
||||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
|
||||||
# void response, no need to return anything
|
|
||||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
|
||||||
Response$new("API client error", resp)
|
|
||||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
|
||||||
Response$new("API server error", resp)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
@ -1,120 +0,0 @@
|
|||||||
# Swagger Petstore
|
|
||||||
#
|
|
||||||
# This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
|
|
||||||
#
|
|
||||||
# OpenAPI spec version: 1.0.0
|
|
||||||
# Contact: apiteam@swagger.io
|
|
||||||
# Generated by: https://github.com/swagger-api/swagger-codegen.git
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#' Pet Class
|
|
||||||
#' @export
|
|
||||||
Pet <- R6::R6Class(
|
|
||||||
'Pet',
|
|
||||||
public = list(
|
|
||||||
`id` = NULL,
|
|
||||||
`category` = NULL,
|
|
||||||
`name` = NULL,
|
|
||||||
`photoUrls` = NULL,
|
|
||||||
`tags` = NULL,
|
|
||||||
`status` = NULL,
|
|
||||||
initialize = function(`id`, `category`, `name`, `photoUrls`, `tags`, `status`){
|
|
||||||
if (!missing(`id`)) {
|
|
||||||
stopifnot(is.numeric(`id`), length(`id`) == 1)
|
|
||||||
self$`id` <- `id`
|
|
||||||
}
|
|
||||||
if (!missing(`category`)) {
|
|
||||||
stopifnot(is.list(tags), length(tags) != 0)
|
|
||||||
lapply(`category`, function(x) stopifnot("Element" %in% class(x), !is.list(x)))
|
|
||||||
self$`category` <- `category`
|
|
||||||
}
|
|
||||||
if (!missing(`name`)) {
|
|
||||||
stopifnot(is.character(`name`), length(`name`) == 1)
|
|
||||||
self$`name` <- `name`
|
|
||||||
}
|
|
||||||
if (!missing(`photoUrls`)) {
|
|
||||||
stopifnot(is.list(`photoUrls`), length(`photoUrls`) != 0)
|
|
||||||
lapply(`photoUrls`, function(x) stopifnot(is.character(x)))
|
|
||||||
self$`photoUrls` <- `photoUrls`
|
|
||||||
}
|
|
||||||
if (!missing(`tags`)) {
|
|
||||||
stopifnot(is.list(tags), length(tags) != 0)
|
|
||||||
lapply(`tags`, function(x) stopifnot("Element" %in% class(x), !is.list(x)))
|
|
||||||
self$`tags` <- `tags`
|
|
||||||
}
|
|
||||||
if (!missing(`status`)) {
|
|
||||||
stopifnot(is.character(`status`), length(`status`) == 1)
|
|
||||||
self$`status` <- `status`
|
|
||||||
}
|
|
||||||
},
|
|
||||||
toJSON = function() {
|
|
||||||
sprintf(
|
|
||||||
'{
|
|
||||||
"id": %d,
|
|
||||||
"category": %s,
|
|
||||||
"name": "%s",
|
|
||||||
"photoUrls": ["%s"],
|
|
||||||
"tags": [%s],
|
|
||||||
"status": "%s"
|
|
||||||
}',
|
|
||||||
self$`id`,
|
|
||||||
self$`category`$toJSON(),
|
|
||||||
self$`name`,
|
|
||||||
lapply(self$`photoUrls`, function(x) paste(paste0('"', x, '"'), sep=",")),
|
|
||||||
lapply(self$`tags`, function(x) paste(x$toJSON(), sep=",")),
|
|
||||||
self$`status`
|
|
||||||
)
|
|
||||||
},
|
|
||||||
fromJSON = function(PetJson) {
|
|
||||||
PetObject <- jsonlite::fromJSON(PetJson)
|
|
||||||
self$`id` <- PetObject$`id`
|
|
||||||
self$`category` <- Category$new()$fromJSON(jsonlite::toJSON(PetObject$category))
|
|
||||||
self$`name` <- PetObject$`name`
|
|
||||||
self$`photoUrls` <- PetObject$`photoUrls`
|
|
||||||
self$`tags` <- lapply(PetObject$`tags`, function(x) Tag$new()$fromJSON(jsonlite::toJSON(x)))
|
|
||||||
self$`status` <- PetObject$`status`
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
#' Element Class
|
|
||||||
#'
|
|
||||||
#' Element Class
|
|
||||||
#' @export
|
|
||||||
Element <- R6::R6Class(
|
|
||||||
'Element',
|
|
||||||
public = list(
|
|
||||||
id = NULL,
|
|
||||||
name = NULL,
|
|
||||||
initialize = function(id,name){
|
|
||||||
if (!missing(id)) {
|
|
||||||
stopifnot(is.numeric(id), length(id) == 1)
|
|
||||||
self$id <- id
|
|
||||||
}
|
|
||||||
if (!missing(name)) {
|
|
||||||
stopifnot(is.character(name), length(name) == 1)
|
|
||||||
self$name <- name
|
|
||||||
}
|
|
||||||
},
|
|
||||||
toJSON = function() {
|
|
||||||
sprintf('{"id":%d,"name":"%s"}', self$id, self$name)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
#' Response Class
|
|
||||||
#'
|
|
||||||
#' Response Class
|
|
||||||
#' @export
|
|
||||||
Response <- R6::R6Class(
|
|
||||||
'Response',
|
|
||||||
public = list(
|
|
||||||
content = NULL,
|
|
||||||
response = NULL,
|
|
||||||
initialize = function(content, response){
|
|
||||||
self$content <- content
|
|
||||||
self$response <- response
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
@ -1,95 +0,0 @@
|
|||||||
#' Pet Store Client Class
|
|
||||||
#'
|
|
||||||
#' Pet Store Client Class
|
|
||||||
#' @export
|
|
||||||
PetStoreClient <- R6::R6Class(
|
|
||||||
'PetStoreClient',
|
|
||||||
public = list(
|
|
||||||
host = NULL,
|
|
||||||
basePath = NULL,
|
|
||||||
scheme = NULL,
|
|
||||||
url = NULL,
|
|
||||||
initialize = function(host, basePath, scheme){
|
|
||||||
self$host <- host
|
|
||||||
self$basePath <- basePath
|
|
||||||
self$scheme <- scheme
|
|
||||||
self$url <- sprintf("%s://%s/%s/pet/", scheme, host, basePath)
|
|
||||||
},
|
|
||||||
getPetById = function(petId){
|
|
||||||
resp <- httr::GET(paste0(self$url, petId), httr::add_headers("accept" = "application/json"))
|
|
||||||
if (httr::http_type(resp) != "application/json") {
|
|
||||||
stop("API did not return json", call. = FALSE)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (httr::status_code(resp) == 200)
|
|
||||||
{
|
|
||||||
parsed <- jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"),
|
|
||||||
simplifyVector = FALSE)
|
|
||||||
pet <- Pet$new(parsed$id,
|
|
||||||
Element$new(parsed$category$id, parsed$category$name),
|
|
||||||
parsed$name,
|
|
||||||
parsed$photoUrls,
|
|
||||||
lapply(parsed$tags, function(x) Element$new(x$id, x$name)),
|
|
||||||
parsed$status)
|
|
||||||
Response$new(pet, resp)
|
|
||||||
}
|
|
||||||
else if(httr::status_code(resp) == 400)
|
|
||||||
{
|
|
||||||
Response$new("Invalid ID supplied", resp)
|
|
||||||
}
|
|
||||||
else if(httr::status_code(resp) == 404)
|
|
||||||
{
|
|
||||||
Response$new("Pet not found", resp)
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Response$new("Unexpected response status code", resp)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
updatePetWithForm = function(petId, name, status){
|
|
||||||
resp <- httr::POST(paste0(self$url, petId),
|
|
||||||
httr::add_headers("accept" = "application/json",
|
|
||||||
"content-type" = "application/x-www-form-urlencoded"),
|
|
||||||
body = list(name = name,
|
|
||||||
status = status))
|
|
||||||
if (httr::http_type(resp) != "application/json") {
|
|
||||||
stop("API did not return json", call. = FALSE)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (httr::status_code(resp) == 200)
|
|
||||||
{
|
|
||||||
Response$new("Pet updated", resp)
|
|
||||||
}
|
|
||||||
else if(httr::status_code(resp) == 405)
|
|
||||||
{
|
|
||||||
Response$new("Invalid input", resp)
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Response$new("Unexpected response status code", resp)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
addPet = function(pet){
|
|
||||||
resp <- httr::POST(self$url,
|
|
||||||
httr::add_headers("accept" = "application/json",
|
|
||||||
"content-type" = "application/json"),
|
|
||||||
body = pet$toJson())
|
|
||||||
if (httr::http_type(resp) != "application/json") {
|
|
||||||
stop("API did not return json", call. = FALSE)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (httr::status_code(resp) == 200)
|
|
||||||
{
|
|
||||||
Response$new("Pet added", resp)
|
|
||||||
}
|
|
||||||
else if(httr::status_code(resp) == 405)
|
|
||||||
{
|
|
||||||
Response$new("Invalid input", resp)
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Response$new("Unexpected response status code", resp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
@ -1,33 +0,0 @@
|
|||||||
# R API client for swagger
|
|
||||||
|
|
||||||
This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
|
|
||||||
|
|
||||||
## Overview
|
|
||||||
This API client was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the [OpenAPI/Swagger spec](https://github.com/swagger-api/swagger-spec) from a remote server, you can easily generate an API client.
|
|
||||||
|
|
||||||
- API version: 1.0.0
|
|
||||||
- Package version: 1.0.0
|
|
||||||
- Build package: io.swagger.codegen.languages.RClientCodegen
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
You'll need the `devtools` package in order to build the API.
|
|
||||||
Make sure you have a proper CRAN repository from which you can download packages.
|
|
||||||
|
|
||||||
### Prerequisites
|
|
||||||
Install the `devtools` package with the following command.
|
|
||||||
```R
|
|
||||||
if(!require(devtools)) { install.packages("devtools") }
|
|
||||||
```
|
|
||||||
|
|
||||||
### Installation of the API package
|
|
||||||
Make sure you set the working directory to where the API code is located.
|
|
||||||
Then execute
|
|
||||||
```R
|
|
||||||
library(devtools)
|
|
||||||
install(".")
|
|
||||||
```
|
|
||||||
|
|
||||||
## Author
|
|
||||||
|
|
||||||
apiteam@swagger.io
|
|
||||||
|
|
@ -1,52 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
|
|
||||||
#
|
|
||||||
# Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update"
|
|
||||||
|
|
||||||
git_user_id=$1
|
|
||||||
git_repo_id=$2
|
|
||||||
release_note=$3
|
|
||||||
|
|
||||||
if [ "$git_user_id" = "" ]; then
|
|
||||||
git_user_id="GIT_USER_ID"
|
|
||||||
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$git_repo_id" = "" ]; then
|
|
||||||
git_repo_id="GIT_REPO_ID"
|
|
||||||
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$release_note" = "" ]; then
|
|
||||||
release_note="Minor update"
|
|
||||||
echo "[INFO] No command line input provided. Set \$release_note to $release_note"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Initialize the local directory as a Git repository
|
|
||||||
git init
|
|
||||||
|
|
||||||
# Adds the files in the local repository and stages them for commit.
|
|
||||||
git add .
|
|
||||||
|
|
||||||
# Commits the tracked changes and prepares them to be pushed to a remote repository.
|
|
||||||
git commit -m "$release_note"
|
|
||||||
|
|
||||||
# Sets the new remote
|
|
||||||
git_remote=`git remote`
|
|
||||||
if [ "$git_remote" = "" ]; then # git remote not defined
|
|
||||||
|
|
||||||
if [ "$GIT_TOKEN" = "" ]; then
|
|
||||||
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git crediential in your environment."
|
|
||||||
git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git
|
|
||||||
else
|
|
||||||
git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git
|
|
||||||
fi
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
git pull origin master
|
|
||||||
|
|
||||||
# Pushes (Forces) the changes in the local repository up to the remote repository
|
|
||||||
echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git"
|
|
||||||
git push origin master 2>&1 | grep -v 'To https'
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
|||||||
% Generated by roxygen2: do not edit by hand
|
|
||||||
% Please edit documentation in R/ApiResponse.r, R/Category.r, R/Order.r,
|
|
||||||
% R/Tag.r, R/User.r, R/pet.R
|
|
||||||
\docType{data}
|
|
||||||
\name{Element}
|
|
||||||
\alias{Element}
|
|
||||||
\alias{Element}
|
|
||||||
\alias{Element}
|
|
||||||
\alias{Element}
|
|
||||||
\alias{Element}
|
|
||||||
\alias{Element}
|
|
||||||
\title{Element Class}
|
|
||||||
\format{An object of class \code{R6ClassGenerator} of length 24.}
|
|
||||||
\usage{
|
|
||||||
Element
|
|
||||||
|
|
||||||
Element
|
|
||||||
|
|
||||||
Element
|
|
||||||
|
|
||||||
Element
|
|
||||||
|
|
||||||
Element
|
|
||||||
|
|
||||||
Element
|
|
||||||
}
|
|
||||||
\description{
|
|
||||||
Element Class
|
|
||||||
|
|
||||||
Element Class
|
|
||||||
|
|
||||||
Element Class
|
|
||||||
|
|
||||||
Element Class
|
|
||||||
|
|
||||||
Element Class
|
|
||||||
|
|
||||||
Element Class
|
|
||||||
}
|
|
||||||
\keyword{datasets}
|
|
@ -1,14 +0,0 @@
|
|||||||
% Generated by roxygen2: do not edit by hand
|
|
||||||
% Please edit documentation in R/pet.R
|
|
||||||
\docType{data}
|
|
||||||
\name{Pet}
|
|
||||||
\alias{Pet}
|
|
||||||
\title{Pet Class}
|
|
||||||
\format{An object of class \code{R6ClassGenerator} of length 24.}
|
|
||||||
\usage{
|
|
||||||
Pet
|
|
||||||
}
|
|
||||||
\description{
|
|
||||||
Pet Class
|
|
||||||
}
|
|
||||||
\keyword{datasets}
|
|
@ -1,14 +0,0 @@
|
|||||||
% Generated by roxygen2: do not edit by hand
|
|
||||||
% Please edit documentation in R/petstore.R
|
|
||||||
\docType{data}
|
|
||||||
\name{PetStoreClient}
|
|
||||||
\alias{PetStoreClient}
|
|
||||||
\title{Pet Store Client Class}
|
|
||||||
\format{An object of class \code{R6ClassGenerator} of length 24.}
|
|
||||||
\usage{
|
|
||||||
PetStoreClient
|
|
||||||
}
|
|
||||||
\description{
|
|
||||||
Pet Store Client Class
|
|
||||||
}
|
|
||||||
\keyword{datasets}
|
|
@ -1,40 +0,0 @@
|
|||||||
% Generated by roxygen2: do not edit by hand
|
|
||||||
% Please edit documentation in R/ApiResponse.r, R/Category.r, R/Order.r,
|
|
||||||
% R/Tag.r, R/User.r, R/pet.R
|
|
||||||
\docType{data}
|
|
||||||
\name{Response}
|
|
||||||
\alias{Response}
|
|
||||||
\alias{Response}
|
|
||||||
\alias{Response}
|
|
||||||
\alias{Response}
|
|
||||||
\alias{Response}
|
|
||||||
\alias{Response}
|
|
||||||
\title{Response Class}
|
|
||||||
\format{An object of class \code{R6ClassGenerator} of length 24.}
|
|
||||||
\usage{
|
|
||||||
Response
|
|
||||||
|
|
||||||
Response
|
|
||||||
|
|
||||||
Response
|
|
||||||
|
|
||||||
Response
|
|
||||||
|
|
||||||
Response
|
|
||||||
|
|
||||||
Response
|
|
||||||
}
|
|
||||||
\description{
|
|
||||||
Response Class
|
|
||||||
|
|
||||||
Response Class
|
|
||||||
|
|
||||||
Response Class
|
|
||||||
|
|
||||||
Response Class
|
|
||||||
|
|
||||||
Response Class
|
|
||||||
|
|
||||||
Response Class
|
|
||||||
}
|
|
||||||
\keyword{datasets}
|
|
@ -1,21 +0,0 @@
|
|||||||
Version: 1.0
|
|
||||||
|
|
||||||
RestoreWorkspace: No
|
|
||||||
SaveWorkspace: No
|
|
||||||
AlwaysSaveHistory: Default
|
|
||||||
|
|
||||||
EnableCodeIndexing: Yes
|
|
||||||
UseSpacesForTab: Yes
|
|
||||||
NumSpacesForTab: 4
|
|
||||||
Encoding: UTF-8
|
|
||||||
|
|
||||||
RnwWeave: Sweave
|
|
||||||
LaTeX: pdfLaTeX
|
|
||||||
|
|
||||||
AutoAppendNewline: Yes
|
|
||||||
StripTrailingWhitespace: Yes
|
|
||||||
|
|
||||||
BuildType: Package
|
|
||||||
PackageUseDevtools: Yes
|
|
||||||
PackageInstallArgs: --no-multiarch --with-keep.source
|
|
||||||
PackageRoxygenize: rd,collate,namespace
|
|
@ -1,4 +0,0 @@
|
|||||||
library(testthat)
|
|
||||||
library(petstore)
|
|
||||||
|
|
||||||
test_check("petstore")
|
|
@ -1,23 +0,0 @@
|
|||||||
context("basic functionality")
|
|
||||||
petStoreClient <- PetStoreClient$new("petstore.swagger.io", "v2", "http")
|
|
||||||
petId <- sample(1:1000, 1)
|
|
||||||
test_that("addPet", {
|
|
||||||
pet <- Pet$new(petId,
|
|
||||||
Element$new(0,"test"),
|
|
||||||
"test",
|
|
||||||
list("test"),
|
|
||||||
list(Element$new(0, "test")),
|
|
||||||
"available")
|
|
||||||
response <- petStoreClient$addPet(pet)
|
|
||||||
expect_equal(response$content, "Pet added")
|
|
||||||
})
|
|
||||||
|
|
||||||
test_that("getPetById", {
|
|
||||||
response <- petStoreClient$getPetById(petId)
|
|
||||||
expect_equal(response$content$id, petId)
|
|
||||||
})
|
|
||||||
|
|
||||||
test_that("updatePetWithForm", {
|
|
||||||
response <- petStoreClient$updatePetWithForm(petId, "test", "sold")
|
|
||||||
expect_equal(response$content, "Pet updated")
|
|
||||||
})
|
|
46
samples/client/petstore/R/pom.xml
Normal file
46
samples/client/petstore/R/pom.xml
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<project>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>org.openapitools</groupId>
|
||||||
|
<artifactId>RPetstoreClientTests</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<name>R OpenAPI Petstore Client</name>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-dependency-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>copy-dependencies</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>exec-maven-plugin</artifactId>
|
||||||
|
<version>1.2.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>nose-test</id>
|
||||||
|
<phase>integration-test</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>exec</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<executable>bash</executable>
|
||||||
|
<arguments>
|
||||||
|
<argument>test_petstore.bash</argument>
|
||||||
|
</arguments>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
21
samples/client/petstore/R/test_petstore.bash
Normal file
21
samples/client/petstore/R/test_petstore.bash
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
REPO=http://cran.revolutionanalytics.com
|
||||||
|
|
||||||
|
export R_LIBS_USER=$HOME/R
|
||||||
|
|
||||||
|
echo "R lib directory: $R_LIBS_USER"
|
||||||
|
|
||||||
|
mkdir $R_LIBS_USER
|
||||||
|
|
||||||
|
Rscript -e "install.packages('jsonlite', repos='$REPO', lib='$R_LIBS_USER')"
|
||||||
|
Rscript -e "install.packages('httr', repos='$REPO', lib='$R_LIBS_USER')"
|
||||||
|
Rscript -e "install.packages('testthat', repos='$REPO', lib='$R_LIBS_USER')"
|
||||||
|
Rscript -e "install.packages('R6', repos='$REPO', lib='$R_LIBS_USER')"
|
||||||
|
Rscript -e "install.packages('caTools', repos='$REPO', lib='$R_LIBS_USER')"
|
||||||
|
|
||||||
|
R CMD build .
|
||||||
|
R CMD check *tar.gz --no-manual
|
||||||
|
R CMD INSTALL *tar.gz
|
68
samples/client/petstore/R/tests/testthat/test_petstore.R
Normal file
68
samples/client/petstore/R/tests/testthat/test_petstore.R
Normal file
@ -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")
|
||||||
|
#})
|
Loading…
x
Reference in New Issue
Block a user