Add support for allOf in R client generator (#12487)

* add support for all in R client generator

* update samples
This commit is contained in:
William Cheng 2022-05-29 07:22:18 +08:00 committed by GitHub
parent 078232acb5
commit 05d49d9107
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 893 additions and 0 deletions

View File

@ -21,6 +21,9 @@
#' @export
{{classname}} <- R6::R6Class(
'{{classname}}',
{{#parent}}
inherit = {{{.}}},
{{/parent}}
public = list(
{{#vars}}
`{{{baseName}}}` = NULL,

View File

@ -766,3 +766,38 @@ components:
type: string
message:
type: string
Dog:
allOf:
- $ref: '#/components/schemas/Animal'
- type: object
properties:
breed:
type: string
Cat:
allOf:
- $ref: '#/components/schemas/Animal'
- $ref: '#/components/schemas/Address'
- type: object
properties:
declawed:
type: boolean
Address:
type: object
additionalProperties:
type: integer
Animal:
type: object
discriminator:
propertyName: className
required:
- className
properties:
className:
type: string
color:
type: string
default: red
allof_tag_api_response:
allOf:
- $ref: '#/components/schemas/Tag'
- $ref: '#/components/schemas/ApiResponse'

View File

@ -3,9 +3,15 @@
.travis.yml
DESCRIPTION
NAMESPACE
R/allof_tag_api_response.R
R/animal.R
R/api_client.R
R/api_response.R
R/cat.R
R/cat_all_of.R
R/category.R
R/dog.R
R/dog_all_of.R
R/fake_api.R
R/model_api_response.R
R/order.R
@ -16,7 +22,13 @@ R/tag.R
R/user.R
R/user_api.R
README.md
docs/AllofTagApiResponse.md
docs/Animal.md
docs/Cat.md
docs/CatAllOf.md
docs/Category.md
docs/Dog.md
docs/DogAllOf.md
docs/FakeApi.md
docs/ModelApiResponse.md
docs/Order.md

View File

@ -11,7 +11,13 @@ export(ApiClient)
export(ApiResponse)
# Models
export(AllofTagApiResponse)
export(Animal)
export(Cat)
export(CatAllOf)
export(Category)
export(Dog)
export(DogAllOf)
export(ModelApiResponse)
export(Order)
export(Pet)

View File

@ -0,0 +1,156 @@
# OpenAPI Petstore
#
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
#
# The version of the OpenAPI document: 1.0.0
# Generated by: https://openapi-generator.tech
#' @docType class
#' @title AllofTagApiResponse
#'
#' @description AllofTagApiResponse Class
#'
#' @format An \code{R6Class} generator object
#'
#' @field id integer [optional]
#'
#' @field name character [optional]
#'
#' @field code integer [optional]
#'
#' @field type character [optional]
#'
#' @field message character [optional]
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
AllofTagApiResponse <- R6::R6Class(
'AllofTagApiResponse',
public = list(
`id` = NULL,
`name` = NULL,
`code` = NULL,
`type` = NULL,
`message` = NULL,
initialize = function(
`id`=NULL, `name`=NULL, `code`=NULL, `type`=NULL, `message`=NULL, ...
) {
local.optional.var <- list(...)
if (!is.null(`id`)) {
stopifnot(is.numeric(`id`), length(`id`) == 1)
self$`id` <- `id`
}
if (!is.null(`name`)) {
stopifnot(is.character(`name`), length(`name`) == 1)
self$`name` <- `name`
}
if (!is.null(`code`)) {
stopifnot(is.numeric(`code`), length(`code`) == 1)
self$`code` <- `code`
}
if (!is.null(`type`)) {
stopifnot(is.character(`type`), length(`type`) == 1)
self$`type` <- `type`
}
if (!is.null(`message`)) {
stopifnot(is.character(`message`), length(`message`) == 1)
self$`message` <- `message`
}
},
toJSON = function() {
AllofTagApiResponseObject <- list()
if (!is.null(self$`id`)) {
AllofTagApiResponseObject[['id']] <-
self$`id`
}
if (!is.null(self$`name`)) {
AllofTagApiResponseObject[['name']] <-
self$`name`
}
if (!is.null(self$`code`)) {
AllofTagApiResponseObject[['code']] <-
self$`code`
}
if (!is.null(self$`type`)) {
AllofTagApiResponseObject[['type']] <-
self$`type`
}
if (!is.null(self$`message`)) {
AllofTagApiResponseObject[['message']] <-
self$`message`
}
AllofTagApiResponseObject
},
fromJSON = function(AllofTagApiResponseJson) {
AllofTagApiResponseObject <- jsonlite::fromJSON(AllofTagApiResponseJson)
if (!is.null(AllofTagApiResponseObject$`id`)) {
self$`id` <- AllofTagApiResponseObject$`id`
}
if (!is.null(AllofTagApiResponseObject$`name`)) {
self$`name` <- AllofTagApiResponseObject$`name`
}
if (!is.null(AllofTagApiResponseObject$`code`)) {
self$`code` <- AllofTagApiResponseObject$`code`
}
if (!is.null(AllofTagApiResponseObject$`type`)) {
self$`type` <- AllofTagApiResponseObject$`type`
}
if (!is.null(AllofTagApiResponseObject$`message`)) {
self$`message` <- AllofTagApiResponseObject$`message`
}
self
},
toJSONString = function() {
jsoncontent <- c(
if (!is.null(self$`id`)) {
sprintf(
'"id":
%d
',
self$`id`
)},
if (!is.null(self$`name`)) {
sprintf(
'"name":
"%s"
',
self$`name`
)},
if (!is.null(self$`code`)) {
sprintf(
'"code":
%d
',
self$`code`
)},
if (!is.null(self$`type`)) {
sprintf(
'"type":
"%s"
',
self$`type`
)},
if (!is.null(self$`message`)) {
sprintf(
'"message":
"%s"
',
self$`message`
)}
)
jsoncontent <- paste(jsoncontent, collapse = ",")
paste('{', jsoncontent, '}', sep = "")
},
fromJSONString = function(AllofTagApiResponseJson) {
AllofTagApiResponseObject <- jsonlite::fromJSON(AllofTagApiResponseJson)
self$`id` <- AllofTagApiResponseObject$`id`
self$`name` <- AllofTagApiResponseObject$`name`
self$`code` <- AllofTagApiResponseObject$`code`
self$`type` <- AllofTagApiResponseObject$`type`
self$`message` <- AllofTagApiResponseObject$`message`
self
}
)
)

View File

@ -0,0 +1,90 @@
# OpenAPI Petstore
#
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
#
# The version of the OpenAPI document: 1.0.0
# Generated by: https://openapi-generator.tech
#' @docType class
#' @title Animal
#'
#' @description Animal Class
#'
#' @format An \code{R6Class} generator object
#'
#' @field className character
#'
#' @field color character [optional]
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
Animal <- R6::R6Class(
'Animal',
public = list(
`className` = NULL,
`color` = NULL,
initialize = function(
`className`, `color`='red', ...
) {
local.optional.var <- list(...)
if (!missing(`className`)) {
stopifnot(is.character(`className`), length(`className`) == 1)
self$`className` <- `className`
}
if (!is.null(`color`)) {
stopifnot(is.character(`color`), length(`color`) == 1)
self$`color` <- `color`
}
},
toJSON = function() {
AnimalObject <- list()
if (!is.null(self$`className`)) {
AnimalObject[['className']] <-
self$`className`
}
if (!is.null(self$`color`)) {
AnimalObject[['color']] <-
self$`color`
}
AnimalObject
},
fromJSON = function(AnimalJson) {
AnimalObject <- jsonlite::fromJSON(AnimalJson)
if (!is.null(AnimalObject$`className`)) {
self$`className` <- AnimalObject$`className`
}
if (!is.null(AnimalObject$`color`)) {
self$`color` <- AnimalObject$`color`
}
self
},
toJSONString = function() {
jsoncontent <- c(
if (!is.null(self$`className`)) {
sprintf(
'"className":
"%s"
',
self$`className`
)},
if (!is.null(self$`color`)) {
sprintf(
'"color":
"%s"
',
self$`color`
)}
)
jsoncontent <- paste(jsoncontent, collapse = ",")
paste('{', jsoncontent, '}', sep = "")
},
fromJSONString = function(AnimalJson) {
AnimalObject <- jsonlite::fromJSON(AnimalJson)
self$`className` <- AnimalObject$`className`
self$`color` <- AnimalObject$`color`
self
}
)
)

View File

@ -0,0 +1,113 @@
# OpenAPI Petstore
#
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
#
# The version of the OpenAPI document: 1.0.0
# Generated by: https://openapi-generator.tech
#' @docType class
#' @title Cat
#'
#' @description Cat Class
#'
#' @format An \code{R6Class} generator object
#'
#' @field className character
#'
#' @field color character [optional]
#'
#' @field declawed character [optional]
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
Cat <- R6::R6Class(
'Cat',
inherit = Animal,
public = list(
`className` = NULL,
`color` = NULL,
`declawed` = NULL,
initialize = function(
`className`, `color`='red', `declawed`=NULL, ...
) {
local.optional.var <- list(...)
if (!missing(`className`)) {
stopifnot(is.character(`className`), length(`className`) == 1)
self$`className` <- `className`
}
if (!is.null(`color`)) {
stopifnot(is.character(`color`), length(`color`) == 1)
self$`color` <- `color`
}
if (!is.null(`declawed`)) {
stopifnot(is.logical(`declawed`), length(`declawed`) == 1)
self$`declawed` <- `declawed`
}
},
toJSON = function() {
CatObject <- list()
if (!is.null(self$`className`)) {
CatObject[['className']] <-
self$`className`
}
if (!is.null(self$`color`)) {
CatObject[['color']] <-
self$`color`
}
if (!is.null(self$`declawed`)) {
CatObject[['declawed']] <-
self$`declawed`
}
CatObject
},
fromJSON = function(CatJson) {
CatObject <- jsonlite::fromJSON(CatJson)
if (!is.null(CatObject$`className`)) {
self$`className` <- CatObject$`className`
}
if (!is.null(CatObject$`color`)) {
self$`color` <- CatObject$`color`
}
if (!is.null(CatObject$`declawed`)) {
self$`declawed` <- CatObject$`declawed`
}
self
},
toJSONString = function() {
jsoncontent <- c(
if (!is.null(self$`className`)) {
sprintf(
'"className":
"%s"
',
self$`className`
)},
if (!is.null(self$`color`)) {
sprintf(
'"color":
"%s"
',
self$`color`
)},
if (!is.null(self$`declawed`)) {
sprintf(
'"declawed":
%s
',
tolower(self$`declawed`)
)}
)
jsoncontent <- paste(jsoncontent, collapse = ",")
paste('{', jsoncontent, '}', sep = "")
},
fromJSONString = function(CatJson) {
CatObject <- jsonlite::fromJSON(CatJson)
self$`className` <- CatObject$`className`
self$`color` <- CatObject$`color`
self$`declawed` <- CatObject$`declawed`
self
}
)
)

View File

@ -0,0 +1,68 @@
# OpenAPI Petstore
#
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
#
# The version of the OpenAPI document: 1.0.0
# Generated by: https://openapi-generator.tech
#' @docType class
#' @title CatAllOf
#'
#' @description CatAllOf Class
#'
#' @format An \code{R6Class} generator object
#'
#' @field declawed character [optional]
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
CatAllOf <- R6::R6Class(
'CatAllOf',
public = list(
`declawed` = NULL,
initialize = function(
`declawed`=NULL, ...
) {
local.optional.var <- list(...)
if (!is.null(`declawed`)) {
stopifnot(is.logical(`declawed`), length(`declawed`) == 1)
self$`declawed` <- `declawed`
}
},
toJSON = function() {
CatAllOfObject <- list()
if (!is.null(self$`declawed`)) {
CatAllOfObject[['declawed']] <-
self$`declawed`
}
CatAllOfObject
},
fromJSON = function(CatAllOfJson) {
CatAllOfObject <- jsonlite::fromJSON(CatAllOfJson)
if (!is.null(CatAllOfObject$`declawed`)) {
self$`declawed` <- CatAllOfObject$`declawed`
}
self
},
toJSONString = function() {
jsoncontent <- c(
if (!is.null(self$`declawed`)) {
sprintf(
'"declawed":
%s
',
tolower(self$`declawed`)
)}
)
jsoncontent <- paste(jsoncontent, collapse = ",")
paste('{', jsoncontent, '}', sep = "")
},
fromJSONString = function(CatAllOfJson) {
CatAllOfObject <- jsonlite::fromJSON(CatAllOfJson)
self$`declawed` <- CatAllOfObject$`declawed`
self
}
)
)

View File

@ -0,0 +1,113 @@
# OpenAPI Petstore
#
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
#
# The version of the OpenAPI document: 1.0.0
# Generated by: https://openapi-generator.tech
#' @docType class
#' @title Dog
#'
#' @description Dog Class
#'
#' @format An \code{R6Class} generator object
#'
#' @field className character
#'
#' @field color character [optional]
#'
#' @field breed character [optional]
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
Dog <- R6::R6Class(
'Dog',
inherit = Animal,
public = list(
`className` = NULL,
`color` = NULL,
`breed` = NULL,
initialize = function(
`className`, `color`='red', `breed`=NULL, ...
) {
local.optional.var <- list(...)
if (!missing(`className`)) {
stopifnot(is.character(`className`), length(`className`) == 1)
self$`className` <- `className`
}
if (!is.null(`color`)) {
stopifnot(is.character(`color`), length(`color`) == 1)
self$`color` <- `color`
}
if (!is.null(`breed`)) {
stopifnot(is.character(`breed`), length(`breed`) == 1)
self$`breed` <- `breed`
}
},
toJSON = function() {
DogObject <- list()
if (!is.null(self$`className`)) {
DogObject[['className']] <-
self$`className`
}
if (!is.null(self$`color`)) {
DogObject[['color']] <-
self$`color`
}
if (!is.null(self$`breed`)) {
DogObject[['breed']] <-
self$`breed`
}
DogObject
},
fromJSON = function(DogJson) {
DogObject <- jsonlite::fromJSON(DogJson)
if (!is.null(DogObject$`className`)) {
self$`className` <- DogObject$`className`
}
if (!is.null(DogObject$`color`)) {
self$`color` <- DogObject$`color`
}
if (!is.null(DogObject$`breed`)) {
self$`breed` <- DogObject$`breed`
}
self
},
toJSONString = function() {
jsoncontent <- c(
if (!is.null(self$`className`)) {
sprintf(
'"className":
"%s"
',
self$`className`
)},
if (!is.null(self$`color`)) {
sprintf(
'"color":
"%s"
',
self$`color`
)},
if (!is.null(self$`breed`)) {
sprintf(
'"breed":
"%s"
',
self$`breed`
)}
)
jsoncontent <- paste(jsoncontent, collapse = ",")
paste('{', jsoncontent, '}', sep = "")
},
fromJSONString = function(DogJson) {
DogObject <- jsonlite::fromJSON(DogJson)
self$`className` <- DogObject$`className`
self$`color` <- DogObject$`color`
self$`breed` <- DogObject$`breed`
self
}
)
)

View File

@ -0,0 +1,68 @@
# OpenAPI Petstore
#
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
#
# The version of the OpenAPI document: 1.0.0
# Generated by: https://openapi-generator.tech
#' @docType class
#' @title DogAllOf
#'
#' @description DogAllOf Class
#'
#' @format An \code{R6Class} generator object
#'
#' @field breed character [optional]
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
DogAllOf <- R6::R6Class(
'DogAllOf',
public = list(
`breed` = NULL,
initialize = function(
`breed`=NULL, ...
) {
local.optional.var <- list(...)
if (!is.null(`breed`)) {
stopifnot(is.character(`breed`), length(`breed`) == 1)
self$`breed` <- `breed`
}
},
toJSON = function() {
DogAllOfObject <- list()
if (!is.null(self$`breed`)) {
DogAllOfObject[['breed']] <-
self$`breed`
}
DogAllOfObject
},
fromJSON = function(DogAllOfJson) {
DogAllOfObject <- jsonlite::fromJSON(DogAllOfJson)
if (!is.null(DogAllOfObject$`breed`)) {
self$`breed` <- DogAllOfObject$`breed`
}
self
},
toJSONString = function() {
jsoncontent <- c(
if (!is.null(self$`breed`)) {
sprintf(
'"breed":
"%s"
',
self$`breed`
)}
)
jsoncontent <- paste(jsoncontent, collapse = ",")
paste('{', jsoncontent, '}', sep = "")
},
fromJSONString = function(DogAllOfJson) {
DogAllOfObject <- jsonlite::fromJSON(DogAllOfJson)
self$`breed` <- DogAllOfObject$`breed`
self
}
)
)

View File

@ -81,7 +81,13 @@ Class | Method | HTTP request | Description
## Documentation for Models
- [AllofTagApiResponse](docs/AllofTagApiResponse.md)
- [Animal](docs/Animal.md)
- [Cat](docs/Cat.md)
- [CatAllOf](docs/CatAllOf.md)
- [Category](docs/Category.md)
- [Dog](docs/Dog.md)
- [DogAllOf](docs/DogAllOf.md)
- [ModelApiResponse](docs/ModelApiResponse.md)
- [Order](docs/Order.md)
- [Pet](docs/Pet.md)

View File

@ -0,0 +1,13 @@
# petstore::AllofTagApiResponse
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**id** | **integer** | | [optional]
**name** | **character** | | [optional]
**code** | **integer** | | [optional]
**type** | **character** | | [optional]
**message** | **character** | | [optional]

View File

@ -0,0 +1,10 @@
# petstore::Animal
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**className** | **character** | |
**color** | **character** | | [optional] [default to &#39;red&#39;]

View File

@ -0,0 +1,11 @@
# petstore::Cat
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**className** | **character** | |
**color** | **character** | | [optional] [default to &#39;red&#39;]
**declawed** | **character** | | [optional]

View File

@ -0,0 +1,9 @@
# petstore::CatAllOf
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**declawed** | **character** | | [optional]

View File

@ -0,0 +1,11 @@
# petstore::Dog
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**className** | **character** | |
**color** | **character** | | [optional] [default to &#39;red&#39;]
**breed** | **character** | | [optional]

View File

@ -0,0 +1,9 @@
# petstore::DogAllOf
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**breed** | **character** | | [optional]

View File

@ -0,0 +1,41 @@
# Automatically generated by openapi-generator (https://openapi-generator.tech)
# Please update as you see appropriate
context("Test AllofTagApiResponse")
model_instance <- AllofTagApiResponse$new()
test_that("id", {
# tests for the property `id` (integer)
# uncomment below to test the property
#expect_equal(model.instance$`id`, "EXPECTED_RESULT")
})
test_that("name", {
# tests for the property `name` (character)
# uncomment below to test the property
#expect_equal(model.instance$`name`, "EXPECTED_RESULT")
})
test_that("code", {
# tests for the property `code` (integer)
# uncomment below to test the property
#expect_equal(model.instance$`code`, "EXPECTED_RESULT")
})
test_that("type", {
# tests for the property `type` (character)
# uncomment below to test the property
#expect_equal(model.instance$`type`, "EXPECTED_RESULT")
})
test_that("message", {
# tests for the property `message` (character)
# uncomment below to test the property
#expect_equal(model.instance$`message`, "EXPECTED_RESULT")
})

View File

@ -0,0 +1,20 @@
# Automatically generated by openapi-generator (https://openapi-generator.tech)
# Please update as you see appropriate
context("Test Animal")
model_instance <- Animal$new()
test_that("className", {
# tests for the property `className` (character)
# uncomment below to test the property
#expect_equal(model.instance$`className`, "EXPECTED_RESULT")
})
test_that("color", {
# tests for the property `color` (character)
# uncomment below to test the property
#expect_equal(model.instance$`color`, "EXPECTED_RESULT")
})

View File

@ -0,0 +1,27 @@
# Automatically generated by openapi-generator (https://openapi-generator.tech)
# Please update as you see appropriate
context("Test Cat")
model_instance <- Cat$new()
test_that("className", {
# tests for the property `className` (character)
# uncomment below to test the property
#expect_equal(model.instance$`className`, "EXPECTED_RESULT")
})
test_that("color", {
# tests for the property `color` (character)
# uncomment below to test the property
#expect_equal(model.instance$`color`, "EXPECTED_RESULT")
})
test_that("declawed", {
# tests for the property `declawed` (character)
# uncomment below to test the property
#expect_equal(model.instance$`declawed`, "EXPECTED_RESULT")
})

View File

@ -0,0 +1,13 @@
# Automatically generated by openapi-generator (https://openapi-generator.tech)
# Please update as you see appropriate
context("Test CatAllOf")
model_instance <- CatAllOf$new()
test_that("declawed", {
# tests for the property `declawed` (character)
# uncomment below to test the property
#expect_equal(model.instance$`declawed`, "EXPECTED_RESULT")
})

View File

@ -0,0 +1,27 @@
# Automatically generated by openapi-generator (https://openapi-generator.tech)
# Please update as you see appropriate
context("Test Dog")
model_instance <- Dog$new()
test_that("className", {
# tests for the property `className` (character)
# uncomment below to test the property
#expect_equal(model.instance$`className`, "EXPECTED_RESULT")
})
test_that("color", {
# tests for the property `color` (character)
# uncomment below to test the property
#expect_equal(model.instance$`color`, "EXPECTED_RESULT")
})
test_that("breed", {
# tests for the property `breed` (character)
# uncomment below to test the property
#expect_equal(model.instance$`breed`, "EXPECTED_RESULT")
})

View File

@ -0,0 +1,13 @@
# Automatically generated by openapi-generator (https://openapi-generator.tech)
# Please update as you see appropriate
context("Test DogAllOf")
model_instance <- DogAllOf$new()
test_that("breed", {
# tests for the property `breed` (character)
# uncomment below to test the property
#expect_equal(model.instance$`breed`, "EXPECTED_RESULT")
})

View File

@ -100,6 +100,25 @@ test_that("GetPetById with data_file", {
expect_equal(response$name, "name_test")
})
test_that("Tests allOf", {
# test allOf without discriminator
a1 <- AllofTagApiResponse$new(id = 450, name = "test_cat", code = 200, type = "test_type", message = "test_message")
expect_true(!is.null(a1))
expect_equal(a1$id, 450)
expect_equal(a1$name, "test_cat")
})
test_that("Tests allOf with discriminator", {
# test allOf without discriminator
c1 <- Cat$new(className = "cat", color = "red", declawed = TRUE)
expect_true(!is.null(c1))
expect_equal(c1$className, "cat")
expect_equal(c1$color, "red")
expect_true(c1$declawed)
})
#test_that("GetPetById", {
# pet.id <- pet.id
# pet <- Pet$new(pet.id, NULL, "name_test2",