swagger-api / swagger-api/swagger-codegen

List of enums in Android generator results in broken enum definition

Open
#7,606 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

List of enums in Android generator results in broken enum definition.

Swagger-codegen version

2.3.1.

Swagger declaration file content or url
      "ApplyCommunicationRecipeResult" : {
         "properties" : {
            "ok" : {
               "type" : "boolean"
            },
            "errors" : {
               "type" : "array",
               "items" : {
                  "type" : "string",
                  "enum" : [
                     "NO_DISCOUNT_OR_BAD_DISCOUNT_TYPE",
                     "HAS_PRODUCT_RELATIONS",
                     "NOT_ONE_INPUT_PRODUCT",
                     "NOT_ONE_OUTPUT_PRODUCT",
                     "NOT_ONE_INPUT_BRAND",
                     "NOT_ONE_OUTPUT_BRAND",
                     "COMMUNICATION_HAS_RULES"
                  ]
               }
            }
         },
         "type" : "object"
      }
Command line used for generation
swagger-codegen generate -i spec.json -l android -o out
Steps to reproduce

Run generator with definition like above. The resulting code will look like

@ApiModel(description = "")
public class ApplyCommunicationRecipeResult {
  
  public enum List<ErrorsEnum> {
     NO_DISCOUNT_OR_BAD_DISCOUNT_TYPE,  HAS_PRODUCT_RELATIONS,  NOT_ONE_INPUT_PRODUCT,  NOT_ONE_OUTPUT_PRODUCT,  NOT_ONE_INPUT_BRAND,  NOT_ONE_OUTPUT_BRAND,  COMMUNICATION_HAS_RULES, 
  };

  @SerializedName("errors")
  private List<ErrorsEnum> errors = null;

  // ...

}
Suggest a fix/enhancement

It works in the Java generator.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the swagger-codegen generate -i spec.json -l android -o out command with the declaration and inspect the generated ApplyCommunicationRecipeResult class. Compare the Android output with the Java generator, then verify that the enum declaration is valid Java while the errors field remains a typed list.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.