Skip to content

[BUG][R] Generating R enums results in empty class with no values #3367

@Leo-Rutschmann

Description

@Leo-Rutschmann
Description

I have noticed that R enums are not generated properly, that is, instead of a proper enum structure, an empty class is generated. In it, there is nothing but the to-/fromJSON-methods; the values of the enum - that are specified in the schema - are not present.

openapi-generator version

openapi generator 4.0.1 (gradle plugin)

OpenAPI declaration file content or url

generated with json Schema:

{
  "openapi": "3.0.0",
  "info": {
    "title": "JSON test",
    "version": "1.0.0-SNAPSHOT"
  },
  "paths": {
  },
  "components": {
    "schemas": {
      "EnumTest": {
        "enum": [
          "One",
          "Two",
          "Three"
        ],
        "type": "string"
      }
    }
  }
}
Command line used for generation

task generate_R_test(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
inputSpec = "$rootDir/src/schema/new/test.schema.json".toString()
outputDir = "$rootDir/src/data/r_model/test".toString()
generatorName = 'r'

systemProperties = [
    models: "", // generate only models, but all of them
]

}

Steps to reproduce
  1. use the gradle plugin with the above command to generate the enum
  2. open the enum file (enum_test.R)
  3. see that it generates an empty class without any of the enum values
Related issues/PRs

I have seearched for this issue but not found a similar case for R (only for Javascript, see swagger-api/swagger-codegen#4819, but I do not know how helpful that will be)

Suggest a fix

I am not really familiar with the whole code, but upon looking at the code, I think the problem is that model.moustache is also used to generate enums. Because the values are described differently in the Schema, they might not be recognised properly

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions