swagger-api/swagger-codegen

[Android/Java] Generating Enum Values

Open

#4,278 opened on Nov 28, 2016

View on GitHub
 (2 comments) (0 reactions) (0 assignees)HTML (12,701 stars) (5,474 forks)batch import
Client: AndroidFeature: EnumIssue: Bughelp wanted

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