Skip to content

Generate enums with integer values assigned #2690

@kenjitayama

Description

@kenjitayama

I want to generate enum with integer values assigned.

Swift:

enum Weather: Int {
    case Sunny = 1
    case Cloudy = 2
    case Rainy = 3
}

Java:

public enum Weather {
    Sunny(1),
    Cloudy(2),
    Rainy(3);

    private final int type;

    private Weather(final int price) {
        this.type = type;
    }

    public type getType() {
        return type;
    }
}

But I couldn't figure out how to do this.

In the Swagger 2.0 specs, it references JSON Schema specs for enum.
It says any type can be used, but it seems like type needs to be string for generating enums. Like this:

definitions:
  weather:
    type: object
    required:
      - type
    properties:
      type:
        type: string
        enum:
          - Sunny
          - Cloudy
          - Rainy

If I change type to integer, no enum is generated, and it will be a plain integer property.

Firstly, I couldn't find how to assign integers to enum items using Swagger specs.

Are there any plans or workarounds to support this kind of enum?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions