OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.98k stars 6.6k forks source link

[BUG] R generator handles enums in response payloads incorrectly #13469

Open jlorince opened 2 years ago

jlorince commented 2 years ago

Bug Report Checklist

Description

When a response payload contains an enum value, the R generator seems to produce unusable code.

The code to generate response payload from JSON ends up looking like this:

    fromJSON = function(input_json) {
      this_object <- jsonlite::fromJSON(input_json)
      ...
      if (!is.null(this_object$`status`)) {
        status_object <- ProjectRunStatus$new()
        status_object$fromJSON(jsonlite::toJSON(this_object$status, auto_unbox = TRUE, digits = NA))
        self$`status` <- status_object
      }
      ...

However, the line status_object <- ProjectRunStatus$new() fails because the class for the enumerated value cannot be initialized without a value:

    initialize = function(...) {
      local.optional.var <- list(...)
      val <- unlist(local.optional.var)
      enumvec <- .parse_ProjectRunStatus()
      stopifnot(length(val) == 1L)

      if (!val %in% enumvec)
          stop("Use one of the valid values: ",
              paste0(enumvec, collapse = ", "))
      private$value <- val
    },
openapi-generator version

6.1.0

Generation Details

yarn run openapi-generator-cli generate -i ./generated/openapi.json -o ../../r-sdk --package-name hexApi -g r

Steps to reproduce

See Above

Related issues/PRs
Suggest a fix

I'm not too familiar with classes in R, so I'm not certain, but somehow the code should somehow be updated to not try to instantiate an empty enum class.

wing328 commented 2 years ago

can you please provide a spec to reproduce the issue?