Skip to content

[php][DefaultCodegen.java] Fix invalid enum const names #3524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 7 additions & 0 deletions generate_all_sample_clients.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
for f in bin/*.sh; do
bash "$f" || break
done

for f in bin/openapi3/*.sh; do
bash "$f" || break
done
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,9 @@ public Map<String, Object> postProcessModelsEnum(Map<String, Object> objs) {
List<Map<String, Object>> enumVars = new ArrayList<Map<String, Object>>();
String commonPrefix = findCommonPrefixOfVars(values);
int truncateIdx = commonPrefix.length();
// https://www.regular-expressions.info/floatingpoint.html
Pattern numberPattern = Pattern.compile("^[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?$");

for (Object value : values) {
Map<String, Object> enumVar = new HashMap<String, Object>();
String enumName;
Expand All @@ -366,7 +369,15 @@ public Map<String, Object> postProcessModelsEnum(Map<String, Object> objs) {
enumName = value.toString();
}
}
enumVar.put("name", toEnumVarName(enumName, cm.dataType));

String enumVarName = toEnumVarName(enumName, cm.dataType);
Matcher numberIsMatch = numberPattern.matcher(enumVarName);
if (numberIsMatch.find()) {
enumVar.put("name", "NUMBER_" + enumVarName);
} else {
enumVar.put("name", enumVarName);
}

enumVar.put("value", toEnumValue(value.toString(), cm.dataType));
enumVar.put("isString", isDataTypeString(cm.dataType));
enumVars.add(enumVar);
Expand Down
2 changes: 2 additions & 0 deletions samples/client/petstore/R/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export(ApiResponse)

# Models
export(Category)
export(InlineObject)
export(InlineObject1)
export(ModelApiResponse)
export(Order)
export(Pet)
Expand Down
86 changes: 86 additions & 0 deletions samples/client/petstore/R/R/inline_object.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# 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 InlineObject
#' @description InlineObject Class
#' @format An \code{R6Class} generator object
#' @field name character [optional]
#'
#' @field status character [optional]
#'
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
InlineObject <- R6::R6Class(
'InlineObject',
public = list(
`name` = NULL,
`status` = NULL,
initialize = function(`name`=NULL, `status`=NULL, ...){
local.optional.var <- list(...)
if (!is.null(`name`)) {
stopifnot(is.character(`name`), length(`name`) == 1)
self$`name` <- `name`
}
if (!is.null(`status`)) {
stopifnot(is.character(`status`), length(`status`) == 1)
self$`status` <- `status`
}
},
toJSON = function() {
InlineObjectObject <- list()
if (!is.null(self$`name`)) {
InlineObjectObject[['name']] <-
self$`name`
}
if (!is.null(self$`status`)) {
InlineObjectObject[['status']] <-
self$`status`
}

InlineObjectObject
},
fromJSON = function(InlineObjectJson) {
InlineObjectObject <- jsonlite::fromJSON(InlineObjectJson)
if (!is.null(InlineObjectObject$`name`)) {
self$`name` <- InlineObjectObject$`name`
}
if (!is.null(InlineObjectObject$`status`)) {
self$`status` <- InlineObjectObject$`status`
}
},
toJSONString = function() {
jsoncontent <- c(
if (!is.null(self$`name`)) {
sprintf(
'"name":
"%s"
',
self$`name`
)},
if (!is.null(self$`status`)) {
sprintf(
'"status":
"%s"
',
self$`status`
)}
)
jsoncontent <- paste(jsoncontent, collapse = ",")
paste('{', jsoncontent, '}', sep = "")
},
fromJSONString = function(InlineObjectJson) {
InlineObjectObject <- jsonlite::fromJSON(InlineObjectJson)
self$`name` <- InlineObjectObject$`name`
self$`status` <- InlineObjectObject$`status`
self
}
)
)
85 changes: 85 additions & 0 deletions samples/client/petstore/R/R/inline_object1.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# 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 InlineObject1
#' @description InlineObject1 Class
#' @format An \code{R6Class} generator object
#' @field additionalMetadata character [optional]
#'
#' @field file data.frame [optional]
#'
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
InlineObject1 <- R6::R6Class(
'InlineObject1',
public = list(
`additionalMetadata` = NULL,
`file` = NULL,
initialize = function(`additionalMetadata`=NULL, `file`=NULL, ...){
local.optional.var <- list(...)
if (!is.null(`additionalMetadata`)) {
stopifnot(is.character(`additionalMetadata`), length(`additionalMetadata`) == 1)
self$`additionalMetadata` <- `additionalMetadata`
}
if (!is.null(`file`)) {
self$`file` <- `file`
}
},
toJSON = function() {
InlineObject1Object <- list()
if (!is.null(self$`additionalMetadata`)) {
InlineObject1Object[['additionalMetadata']] <-
self$`additionalMetadata`
}
if (!is.null(self$`file`)) {
InlineObject1Object[['file']] <-
self$`file`
}

InlineObject1Object
},
fromJSON = function(InlineObject1Json) {
InlineObject1Object <- jsonlite::fromJSON(InlineObject1Json)
if (!is.null(InlineObject1Object$`additionalMetadata`)) {
self$`additionalMetadata` <- InlineObject1Object$`additionalMetadata`
}
if (!is.null(InlineObject1Object$`file`)) {
self$`file` <- InlineObject1Object$`file`
}
},
toJSONString = function() {
jsoncontent <- c(
if (!is.null(self$`additionalMetadata`)) {
sprintf(
'"additionalMetadata":
"%s"
',
self$`additionalMetadata`
)},
if (!is.null(self$`file`)) {
sprintf(
'"file":
"%s"
',
self$`file`
)}
)
jsoncontent <- paste(jsoncontent, collapse = ",")
paste('{', jsoncontent, '}', sep = "")
},
fromJSONString = function(InlineObject1Json) {
InlineObject1Object <- jsonlite::fromJSON(InlineObject1Json)
self$`additionalMetadata` <- InlineObject1Object$`additionalMetadata`
self$`file` <- InlineObject1Object$`file`
self
}
)
)
52 changes: 28 additions & 24 deletions samples/client/petstore/R/R/pet_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#'
#'
#' \itemize{
#' \item \emph{ @param } body \link[petstore:Pet]{ Pet }
#' \item \emph{ @param } pet \link[petstore:Pet]{ Pet }
#'
#'
#' \item status code : 405 | Invalid input
Expand Down Expand Up @@ -76,6 +76,7 @@
#'
#' \itemize{
#' \item \emph{ @param } tags list( character )
#' \item \emph{ @param } max.count integer
#' \item \emph{ @returnType } \link[petstore:Pet]{ list(Pet) } \cr
#'
#'
Expand Down Expand Up @@ -130,7 +131,7 @@
#'
#'
#' \itemize{
#' \item \emph{ @param } body \link[petstore:Pet]{ Pet }
#' \item \emph{ @param } pet \link[petstore:Pet]{ Pet }
#'
#'
#' \item status code : 400 | Invalid ID supplied
Expand Down Expand Up @@ -201,15 +202,15 @@
#' #################### AddPet ####################
#'
#' 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';
#'
#' result <- api.instance$AddPet(var.body)
#' result <- api.instance$AddPet(var.pet)
#'
#'
#' #################### DeletePet ####################
Expand Down Expand Up @@ -245,14 +246,15 @@
#'
#' library(petstore)
#' var.tags <- ['tags_example'] # array[character] | Tags to filter by
#' var.max.count <- 56 # integer | Maximum number of items to return
#'
#' #Finds Pets by tags
#' api.instance <- PetApi$new()
#'
#' # Configure OAuth2 access token for authorization: petstore_auth
#' api.instance$apiClient$accessToken <- 'TODO_YOUR_ACCESS_TOKEN';
#'
#' result <- api.instance$FindPetsByTags(var.tags)
#' result <- api.instance$FindPetsByTags(var.tags, max.count=var.max.count)
#'
#'
#' #################### GetPetById ####################
Expand All @@ -272,15 +274,15 @@
#' #################### UpdatePet ####################
#'
#' 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';
#'
#' result <- api.instance$UpdatePet(var.body)
#' result <- api.instance$UpdatePet(var.pet)
#'
#'
#' #################### UpdatePetWithForm ####################
Expand Down Expand Up @@ -331,8 +333,8 @@ PetApi <- R6::R6Class(
self$apiClient <- ApiClient$new()
}
},
AddPet = function(body, ...){
apiResponse <- self$AddPetWithHttpInfo(body, ...)
AddPet = function(pet, ...){
apiResponse <- self$AddPetWithHttpInfo(pet, ...)
resp <- apiResponse$response
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
apiResponse$content
Expand All @@ -343,17 +345,17 @@ PetApi <- R6::R6Class(
}
},

AddPetWithHttpInfo = function(body, ...){
AddPetWithHttpInfo = 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
}
Expand Down Expand Up @@ -471,8 +473,8 @@ PetApi <- R6::R6Class(
ApiResponse$new("API server error", resp)
}
},
FindPetsByTags = function(tags, ...){
apiResponse <- self$FindPetsByTagsWithHttpInfo(tags, ...)
FindPetsByTags = function(tags, max.count=NULL, ...){
apiResponse <- self$FindPetsByTagsWithHttpInfo(tags, max.count, ...)
resp <- apiResponse$response
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
apiResponse$content
Expand All @@ -483,7 +485,7 @@ PetApi <- R6::R6Class(
}
},

FindPetsByTagsWithHttpInfo = function(tags, ...){
FindPetsByTagsWithHttpInfo = function(tags, max.count=NULL, ...){
args <- list(...)
queryParams <- list()
headerParams <- c()
Expand All @@ -494,6 +496,8 @@ PetApi <- R6::R6Class(

queryParams['tags'] <- tags

queryParams['maxCount'] <- max.count

urlPath <- "/pet/findByTags"
# OAuth token
headerParams['Authorization'] <- paste("Bearer", self$apiClient$accessToken, sep=" ")
Expand Down Expand Up @@ -571,8 +575,8 @@ PetApi <- R6::R6Class(
ApiResponse$new("API server error", resp)
}
},
UpdatePet = function(body, ...){
apiResponse <- self$UpdatePetWithHttpInfo(body, ...)
UpdatePet = function(pet, ...){
apiResponse <- self$UpdatePetWithHttpInfo(pet, ...)
resp <- apiResponse$response
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
apiResponse$content
Expand All @@ -583,17 +587,17 @@ PetApi <- R6::R6Class(
}
},

UpdatePetWithHttpInfo = function(body, ...){
UpdatePetWithHttpInfo = 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
}
Expand Down
Loading