swagger-api / swagger-api/swagger-codegen
Generate enums with integer values assigned
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no repository file, test, or generator entry point. Start by reading the cited Swagger 2.0 and JSON Schema enum/type references, then trace how the generator treats integer properties versus string enums. Done means the project has a clear supported approach for preserving integer enum values in generated output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100