swagger-api / swagger-api/swagger-codegen

Enum set with specific int is ignored

Open
#4,256 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

My csharp enum which starts with Regular = 1 becomes Regular = 0 after code is generated.

Swagger-codegen version 2.2.1

csharp class:
public enum UserType
{
Regular = 1,
Admin,
Ad
}

swagger.json:
"enum":["Regular","Admin","Ad"],"type":"string"

Generated code by swagger-codegen-cli:
[JsonConverter(typeof(StringEnumConverter))]
public enum TypeEnum
{
[EnumMember(Value = "Regular")]
Regular,
[EnumMember(Value = "Admin")]
Admin,
[EnumMember(Value = "Ad")]
Ad
}

Command line used for generation

java -jar swagger-codegen-cli.jar generate -i http://localhost:61387/swagger/v1/swagger.json -l csharp -o samples/client/

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 with the supplied swagger.json and the Java CLI command, then compare the generated C# enum with the source declaration. Search the C# generator and its templates for enum handling and check whether existing tests cover explicit enum values. Done means the generated enum preserves the intended values, with a regression test documenting the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, java, openapi
Domain
build-system, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.