swagger-api / swagger-api/swagger-codegen
aspnetcore not generating valid enums
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
aspnetcore server generation does not generate valid c# for enums with string values. eg
"enrollmentStatus":{
"type": "string",
"enum": [
"NotEnrolled",
"Enrolled",
"PendingEligibilityRequirements"
]
}
After running generate command the resultant code:
public enum EnrollmentStatusEnum
{
/// <summary>
/// Enum NotEnrolledEnum for NotEnrolled
/// </summary>
[EnumMember(Value = NotEnrolled)]
NotEnrolledEnum = 1,
/// <summary>
/// Enum EnrolledEnum for Enrolled
/// </summary>
[EnumMember(Value = Enrolled)]
EnrolledEnum = 2,
/// <summary>
/// Enum PendingEligibilityRequirementsEnum for PendingEligibilityRequirements
/// </summary>
[EnumMember(Value = PendingEligibilityRequirements)]
PendingEligibilityRequirementsEnum = 3
}
compiler error: error CS0103: The name 'NotEnrolled' does not exist in the current context [%out_folder%\src\IO.Swagger\IO.Swagger.csproj]
Expected result:
[EnumMember(Value = "NotEnrolled")]
NotEnrolledEnum = 1,
Swagger-codegen version
2.3.1
Swagger declaration file content or url
Command line used for generation
java -jar swagger-codegen-cli.jar generate -i %JSON_CONFIG% -l aspnetcore -o "%APP_FOLDER%API"
Steps to reproduce
Related issues
Suggest a Fix
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
Start by reproducing the issue with the provided JSON enum and the aspnetcore generation command, then inspect the template or generator entry point that produces the EnumMember attributes. Confirm the generated C# compiles and that string enum values are emitted as quoted values such as "NotEnrolled".
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend, tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100