Better null check for encoding (#12597)

* better null check for encoding

* add tests

* update samples
This commit is contained in:
William Cheng 2022-06-15 15:49:30 +08:00 committed by GitHub
parent 6be94becee
commit bd6617b3e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 151 additions and 4 deletions

View File

@ -6836,8 +6836,8 @@ public class DefaultCodegen implements CodegenConfig {
enc.getContentType(),
headers,
enc.getStyle().toString(),
enc.getExplode().booleanValue(),
enc.getAllowReserved().booleanValue()
enc.getExplode() == null ? false : enc.getExplode().booleanValue(),
enc.getAllowReserved() == null ? false : enc.getAllowReserved().booleanValue()
);
String propName = encodingEntry.getKey();
ceMap.put(propName, ce);

View File

@ -618,6 +618,24 @@ components:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
multipart/related: # message with binary body part
schema:
type: object
properties: # Request parts
jsonData:
$ref: '#/components/schemas/Pet'
binaryDataN2Information:
type: string
format: binary
encoding:
jsonData:
contentType: application/json
binaryDataN2Information:
contentType: application/vnd.3gpp.ngap
headers:
Content-Id:
schema:
type: string
description: Pet object that needs to be added to the store
required: true
securitySchemes:

View File

@ -24,6 +24,7 @@ R/pet_api.R
R/pig.R
R/store_api.R
R/tag.R
R/update_pet_request.R
R/user.R
R/user_api.R
README.md
@ -45,6 +46,7 @@ docs/PetApi.md
docs/Pig.md
docs/StoreApi.md
docs/Tag.md
docs/UpdatePetRequest.md
docs/User.md
docs/UserApi.md
git_push.sh

View File

@ -27,6 +27,7 @@ export(Order)
export(Pet)
export(Pig)
export(Tag)
export(UpdatePetRequest)
export(User)
# APIs

View File

@ -0,0 +1,95 @@
# 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 UpdatePetRequest
#'
#' @description UpdatePetRequest Class
#'
#' @format An \code{R6Class} generator object
#'
#' @field jsonData \link{Pet} [optional]
#'
#' @field binaryDataN2Information data.frame [optional]
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
UpdatePetRequest <- R6::R6Class(
'UpdatePetRequest',
public = list(
`jsonData` = NULL,
`binaryDataN2Information` = NULL,
initialize = function(
`jsonData`=NULL, `binaryDataN2Information`=NULL, ...
) {
if (!is.null(`jsonData`)) {
stopifnot(R6::is.R6(`jsonData`))
self$`jsonData` <- `jsonData`
}
if (!is.null(`binaryDataN2Information`)) {
self$`binaryDataN2Information` <- `binaryDataN2Information`
}
},
toJSON = function() {
UpdatePetRequestObject <- list()
if (!is.null(self$`jsonData`)) {
UpdatePetRequestObject[['jsonData']] <-
self$`jsonData`$toJSON()
}
if (!is.null(self$`binaryDataN2Information`)) {
UpdatePetRequestObject[['binaryDataN2Information']] <-
self$`binaryDataN2Information`
}
UpdatePetRequestObject
},
fromJSON = function(UpdatePetRequestJson) {
UpdatePetRequestObject <- jsonlite::fromJSON(UpdatePetRequestJson)
if (!is.null(UpdatePetRequestObject$`jsonData`)) {
jsonDataObject <- Pet$new()
jsonDataObject$fromJSON(jsonlite::toJSON(UpdatePetRequestObject$jsonData, auto_unbox = TRUE, digits = NA))
self$`jsonData` <- jsonDataObject
}
if (!is.null(UpdatePetRequestObject$`binaryDataN2Information`)) {
self$`binaryDataN2Information` <- UpdatePetRequestObject$`binaryDataN2Information`
}
self
},
toJSONString = function() {
jsoncontent <- c(
if (!is.null(self$`jsonData`)) {
sprintf(
'"jsonData":
%s
',
jsonlite::toJSON(self$`jsonData`$toJSON(), auto_unbox=TRUE, digits = NA)
)},
if (!is.null(self$`binaryDataN2Information`)) {
sprintf(
'"binaryDataN2Information":
"%s"
',
self$`binaryDataN2Information`
)}
)
jsoncontent <- paste(jsoncontent, collapse = ",")
paste('{', jsoncontent, '}', sep = "")
},
fromJSONString = function(UpdatePetRequestJson) {
UpdatePetRequestObject <- jsonlite::fromJSON(UpdatePetRequestJson)
self$`jsonData` <- Pet$new()$fromJSON(jsonlite::toJSON(UpdatePetRequestObject$jsonData, auto_unbox = TRUE, digits = NA))
self$`binaryDataN2Information` <- UpdatePetRequestObject$`binaryDataN2Information`
self
},
validateJSON = function(input) {
input_json <- jsonlite::fromJSON(input)
}
)
)

View File

@ -96,6 +96,7 @@ Class | Method | HTTP request | Description
- [Pet](docs/Pet.md)
- [Pig](docs/Pig.md)
- [Tag](docs/Tag.md)
- [UpdatePetRequest](docs/UpdatePetRequest.md)
- [User](docs/User.md)

View File

@ -64,7 +64,7 @@ Name | Type | Description | Notes
### HTTP request headers
- **Content-Type**: application/json, application/xml
- **Content-Type**: application/json, application/xml, multipart/related
- **Accept**: application/xml, application/json
### HTTP response details
@ -359,7 +359,7 @@ Name | Type | Description | Notes
### HTTP request headers
- **Content-Type**: application/json, application/xml
- **Content-Type**: application/json, application/xml, multipart/related
- **Accept**: application/xml, application/json
### HTTP response details

View File

@ -0,0 +1,10 @@
# petstore::UpdatePetRequest
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**jsonData** | [**Pet**](Pet.md) | | [optional]
**binaryDataN2Information** | **data.frame** | | [optional]

View File

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