OpenAPITools / OpenAPITools/openapi-generator
[BUG] R generator handles enums in response payloads incorrectly
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the documented openapi-generator-cli command and the supplied OpenAPI spec. Inspect the R generator output around the response model's fromJSON method and the enum class's initialize method. Done means generated R code can deserialize a response containing an enum without trying to initialize the enum class without a value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100