swagger-api / swagger-api/swagger-codegen

[Android/Java] Generating Enum Values

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

Nobody has claimed this yet.

Client: Android Feature: Enum help wanted Issue: Bug
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

When exporting to Android enums are generated as:

public enum GenderIdEnum {
     0,  1,  2, 
  };

Versus a potential workaround:

public enum GenderIdEnum {
    Zero(0), One(1), Two(2);
    private int value;
    private GenderIdEnum(int value) {
      this.value = value;
    }
    public int getValue() {
      return value;
    }
  };
Swagger-codegen version

Using: http://editor.swagger.io/#/

Loading from URL:
https://polling.arena.razerzone.com/swagger/docs/v1

Exporting to Android.

Importing to Android Studio.

Gradle reports the enum syntax error.

Steps to reproduce
  1. Go to http://editor.swagger.io/

  2. File Import URL:
    https://polling.arena.razerzone.com/swagger/docs/v1

  3. Generate Client Android

  4. Unpack zip file

  5. Import as new project in Android Studio

  6. See the gradle compile error

Related issues

https://github.com/swagger-api/swagger-codegen/issues/4279

Suggest a Fix
public enum GenderIdEnum {
    Zero(0), One(1), Two(2);
    private int value;
    private GenderIdEnum(int value) {
      this.value = value;
    }
    public int getValue() {
      return value;
    }
  };

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

Reproduce the issue by importing the supplied Swagger URL in editor.swagger.io and generating an Android client. Inspect the generated Java enum and the Android generation template or entry point that produces it, then verify completion by importing the client into Android Studio and confirming that Gradle compiles without the enum syntax error.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.