Skip to content

[Android/Java] Generating Enum Values #4278

@tgraupmann

Description

@tgraupmann
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

#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;
    }
  };

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions