[R] Fix NPE issue due to default value using example value (#2231)

* fix NPE issue due to default value using example value

* update r petstore sample
This commit is contained in:
William Cheng 2019-02-25 19:09:26 +08:00 committed by GitHub
parent 8e7ad9c9b6
commit 9695090d9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 73 additions and 104 deletions

View File

@ -551,14 +551,6 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
else
return "TRUE";
}
// include fallback to example, default defined as server only
// example is not defined as server only
if (p.getExample() != null) {
if (Boolean.valueOf(p.getExample().toString()) == false)
return "FALSE";
else
return "TRUE";
}
} else if (ModelUtils.isDateSchema(p)) {
// TODO
} else if (ModelUtils.isDateTimeSchema(p)) {
@ -567,24 +559,10 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
if (p.getDefault() != null) {
return p.getDefault().toString();
}
// default numbers are not yet returned by v2 spec openAPI results
// https://github.com/swagger-api/swagger-parser/issues/971
// include fallback to example, default defined as server only
// example is not defined as server only
if (p.getExample() != null) {
return p.getExample().toString();
}
} else if (ModelUtils.isIntegerSchema(p)) {
if (p.getDefault() != null) {
return p.getDefault().toString();
}
// default integers are not yet returned by v2 spec openAPI results
// https://github.com/swagger-api/swagger-parser/issues/971
// include fallback to example, default defined as server only
// example is not defined as server only
if (p.getExample() != null) {
return p.getExample().toString();
}
} else if (ModelUtils.isStringSchema(p)) {
if (p.getDefault() != null) {
if (Pattern.compile("\r\n|\r|\n").matcher((String) p.getDefault()).find())
@ -592,23 +570,10 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
else
return "'" + p.getDefault() + "'";
}
// include fallback to example, default defined as server only
// example is not defined as server only
if (p.getExample() != null) {
if (Pattern.compile("\r\n|\r|\n").matcher((String) p.getExample()).find())
return "'''" + p.getExample() + "'''";
else
return "'" + p.getExample() + "'";
}
} else if (ModelUtils.isArraySchema(p)) {
if (p.getDefault() != null) {
return p.getDefault().toString();
}
// include fallback to example, default defined as server only
// example is not defined as server only
if (p.getExample() != null) {
return p.getExample().toString();
}
}
return null;

View File

@ -7,6 +7,8 @@ export(ApiResponse)
# Models
export(Category)
export(InlineObject)
export(InlineObject1)
export(ModelApiResponse)
export(Order)
export(Pet)

View File

@ -56,17 +56,17 @@ PetApi <- R6::R6Class(
self$apiClient <- ApiClient$new()
}
},
AddPet = function(body, ...){
AddPet = function(pet, ...){
args <- list(...)
queryParams <- list()
headerParams <- c()
if (missing(`body`)) {
stop("Missing required parameter `body`.")
if (missing(`pet`)) {
stop("Missing required parameter `pet`.")
}
if (!missing(`body`)) {
body <- `body`$toJSONString()
if (!missing(`pet`)) {
body <- `pet`$toJSONString()
} else {
body <- NULL
}
@ -223,17 +223,17 @@ PetApi <- R6::R6Class(
}
},
UpdatePet = function(body, ...){
UpdatePet = function(pet, ...){
args <- list(...)
queryParams <- list()
headerParams <- c()
if (missing(`body`)) {
stop("Missing required parameter `body`.")
if (missing(`pet`)) {
stop("Missing required parameter `pet`.")
}
if (!missing(`body`)) {
body <- `body`$toJSONString()
if (!missing(`pet`)) {
body <- `pet`$toJSONString()
} else {
body <- NULL
}

View File

@ -133,17 +133,17 @@ StoreApi <- R6::R6Class(
}
},
PlaceOrder = function(body, ...){
PlaceOrder = function(order, ...){
args <- list(...)
queryParams <- list()
headerParams <- c()
if (missing(`body`)) {
stop("Missing required parameter `body`.")
if (missing(`order`)) {
stop("Missing required parameter `order`.")
}
if (!missing(`body`)) {
body <- `body`$toJSONString()
if (!missing(`order`)) {
body <- `order`$toJSONString()
} else {
body <- NULL
}

View File

@ -56,17 +56,17 @@ UserApi <- R6::R6Class(
self$apiClient <- ApiClient$new()
}
},
CreateUser = function(body, ...){
CreateUser = function(user, ...){
args <- list(...)
queryParams <- list()
headerParams <- c()
if (missing(`body`)) {
stop("Missing required parameter `body`.")
if (missing(`user`)) {
stop("Missing required parameter `user`.")
}
if (!missing(`body`)) {
body <- `body`$toJSONString()
if (!missing(`user`)) {
body <- `user`$toJSONString()
} else {
body <- NULL
}
@ -89,17 +89,17 @@ UserApi <- R6::R6Class(
}
},
CreateUsersWithArrayInput = function(body, ...){
CreateUsersWithArrayInput = function(user, ...){
args <- list(...)
queryParams <- list()
headerParams <- c()
if (missing(`body`)) {
stop("Missing required parameter `body`.")
if (missing(`user`)) {
stop("Missing required parameter `user`.")
}
if (!missing(`body`)) {
body <- `body`$toJSONString()
if (!missing(`user`)) {
body <- `user`$toJSONString()
} else {
body <- NULL
}
@ -122,17 +122,17 @@ UserApi <- R6::R6Class(
}
},
CreateUsersWithListInput = function(body, ...){
CreateUsersWithListInput = function(user, ...){
args <- list(...)
queryParams <- list()
headerParams <- c()
if (missing(`body`)) {
stop("Missing required parameter `body`.")
if (missing(`user`)) {
stop("Missing required parameter `user`.")
}
if (!missing(`body`)) {
body <- `body`$toJSONString()
if (!missing(`user`)) {
body <- `user`$toJSONString()
} else {
body <- NULL
}
@ -275,7 +275,7 @@ UserApi <- R6::R6Class(
}
},
UpdateUser = function(username, body, ...){
UpdateUser = function(username, user, ...){
args <- list(...)
queryParams <- list()
headerParams <- c()
@ -284,12 +284,12 @@ UserApi <- R6::R6Class(
stop("Missing required parameter `username`.")
}
if (missing(`body`)) {
stop("Missing required parameter `body`.")
if (missing(`user`)) {
stop("Missing required parameter `user`.")
}
if (!missing(`body`)) {
body <- `body`$toJSONString()
if (!missing(`user`)) {
body <- `user`$toJSONString()
} else {
body <- NULL
}

View File

@ -81,6 +81,8 @@ Class | Method | HTTP request | Description
## Documentation for Models
- [Category](docs/Category.md)
- [InlineObject](docs/InlineObject.md)
- [InlineObject1](docs/InlineObject1.md)
- [ModelApiResponse](docs/ModelApiResponse.md)
- [Order](docs/Order.md)
- [Pet](docs/Pet.md)

View File

@ -5,7 +5,7 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**id** | **integer** | | [optional]
**category** | [**Category**](Category.md) | | [optional]
**name** | **character** | | [default to &#39;doggie&#39;]
**name** | **character** | |
**photoUrls** | **character** | |
**tags** | [**Tag**](Tag.md) | | [optional]
**status** | **character** | pet status in the store | [optional]

View File

@ -15,7 +15,7 @@ Method | HTTP request | Description
# **AddPet**
> AddPet(body)
> AddPet(pet)
Add a new pet to the store
@ -23,20 +23,20 @@ Add a new pet to the store
```R
library(petstore)
var.body <- Pet$new() # Pet | Pet object that needs to be added to the store
var.pet <- Pet$new() # Pet | Pet object that needs to be added to the store
#Add a new pet to the store
api.instance <- PetApi$new()
# Configure OAuth2 access token for authorization: petstore_auth
api.instance$apiClient$accessToken <- 'TODO_YOUR_ACCESS_TOKEN';
api.instance$AddPet(var.body)
api.instance$AddPet(var.pet)
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**body** | [**Pet**](Pet.md)| Pet object that needs to be added to the store |
**pet** | [**Pet**](Pet.md)| Pet object that needs to be added to the store |
### Return type
@ -221,7 +221,7 @@ Name | Type | Description | Notes
# **UpdatePet**
> UpdatePet(body)
> UpdatePet(pet)
Update an existing pet
@ -229,20 +229,20 @@ Update an existing pet
```R
library(petstore)
var.body <- Pet$new() # Pet | Pet object that needs to be added to the store
var.pet <- Pet$new() # Pet | Pet object that needs to be added to the store
#Update an existing pet
api.instance <- PetApi$new()
# Configure OAuth2 access token for authorization: petstore_auth
api.instance$apiClient$accessToken <- 'TODO_YOUR_ACCESS_TOKEN';
api.instance$UpdatePet(var.body)
api.instance$UpdatePet(var.pet)
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**body** | [**Pet**](Pet.md)| Pet object that needs to be added to the store |
**pet** | [**Pet**](Pet.md)| Pet object that needs to be added to the store |
### Return type

View File

@ -128,7 +128,7 @@ No authorization required
# **PlaceOrder**
> Order PlaceOrder(body)
> Order PlaceOrder(order)
Place an order for a pet
@ -136,11 +136,11 @@ Place an order for a pet
```R
library(petstore)
var.body <- Order$new() # Order | order placed for purchasing the pet
var.order <- Order$new() # Order | order placed for purchasing the pet
#Place an order for a pet
api.instance <- StoreApi$new()
result <- api.instance$PlaceOrder(var.body)
result <- api.instance$PlaceOrder(var.order)
dput(result)
```
@ -148,7 +148,7 @@ dput(result)
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**body** | [**Order**](Order.md)| order placed for purchasing the pet |
**order** | [**Order**](Order.md)| order placed for purchasing the pet |
### Return type
@ -160,7 +160,7 @@ No authorization required
### HTTP request headers
- **Content-Type**: Not defined
- **Content-Type**: application/json
- **Accept**: application/xml, application/json

View File

@ -15,7 +15,7 @@ Method | HTTP request | Description
# **CreateUser**
> CreateUser(body)
> CreateUser(user)
Create user
@ -25,18 +25,18 @@ This can only be done by the logged in user.
```R
library(petstore)
var.body <- User$new() # User | Created user object
var.user <- User$new() # User | Created user object
#Create user
api.instance <- UserApi$new()
api.instance$CreateUser(var.body)
api.instance$CreateUser(var.user)
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**body** | [**User**](User.md)| Created user object |
**user** | [**User**](User.md)| Created user object |
### Return type
@ -48,13 +48,13 @@ No authorization required
### HTTP request headers
- **Content-Type**: Not defined
- **Content-Type**: application/json
- **Accept**: Not defined
# **CreateUsersWithArrayInput**
> CreateUsersWithArrayInput(body)
> CreateUsersWithArrayInput(user)
Creates list of users with given input array
@ -62,18 +62,18 @@ Creates list of users with given input array
```R
library(petstore)
var.body <- [array$new()] # User | List of user object
var.user <- [array$new()] # User | List of user object
#Creates list of users with given input array
api.instance <- UserApi$new()
api.instance$CreateUsersWithArrayInput(var.body)
api.instance$CreateUsersWithArrayInput(var.user)
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**body** | [**User**](array.md)| List of user object |
**user** | [**User**](array.md)| List of user object |
### Return type
@ -85,13 +85,13 @@ No authorization required
### HTTP request headers
- **Content-Type**: Not defined
- **Content-Type**: application/json
- **Accept**: Not defined
# **CreateUsersWithListInput**
> CreateUsersWithListInput(body)
> CreateUsersWithListInput(user)
Creates list of users with given input array
@ -99,18 +99,18 @@ Creates list of users with given input array
```R
library(petstore)
var.body <- [array$new()] # User | List of user object
var.user <- [array$new()] # User | List of user object
#Creates list of users with given input array
api.instance <- UserApi$new()
api.instance$CreateUsersWithListInput(var.body)
api.instance$CreateUsersWithListInput(var.user)
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**body** | [**User**](array.md)| List of user object |
**user** | [**User**](array.md)| List of user object |
### Return type
@ -122,7 +122,7 @@ No authorization required
### HTTP request headers
- **Content-Type**: Not defined
- **Content-Type**: application/json
- **Accept**: Not defined
@ -278,7 +278,7 @@ No authorization required
# **UpdateUser**
> UpdateUser(username, body)
> UpdateUser(username, user)
Updated user
@ -289,11 +289,11 @@ This can only be done by the logged in user.
library(petstore)
var.username <- 'username_example' # character | name that need to be deleted
var.body <- User$new() # User | Updated user object
var.user <- User$new() # User | Updated user object
#Updated user
api.instance <- UserApi$new()
api.instance$UpdateUser(var.username, var.body)
api.instance$UpdateUser(var.username, var.user)
```
### Parameters
@ -301,7 +301,7 @@ api.instance$UpdateUser(var.username, var.body)
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**username** | **character**| name that need to be deleted |
**body** | [**User**](User.md)| Updated user object |
**user** | [**User**](User.md)| Updated user object |
### Return type
@ -313,7 +313,7 @@ No authorization required
### HTTP request headers
- **Content-Type**: Not defined
- **Content-Type**: application/json
- **Accept**: Not defined