swagger-api / swagger-api/swagger-codegen
[aspnetcore] string enums are invalid
Open
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
C# auto generated aspnetcore project contains invalid enums
Swagger-codegen version
2.3.1
Swagger declaration file content or url
Gist here
yaml code
status:
type: "string"
description: "pet status in the store"
enum:
- "available"
- "pending"
- "sold"
Command line used for generation
editor.swagger.io
Steps to reproduce
- Take code from gist
- Paste into editor.swagger.io (http, not https)
- Generate an
aspnetcoreserver - Model generated looks like the following:
public enum StatusEnum
{
/// <summary>
/// Enum AvailableEnum for available
/// </summary>
[EnumMember(Value = available)]
AvailableEnum = 1,
/// <summary>
/// Enum PendingEnum for pending
/// </summary>
[EnumMember(Value = pending)]
PendingEnum = 2,
/// <summary>
/// Enum SoldEnum for sold
/// </summary>
[EnumMember(Value = sold)]
SoldEnum = 3
}
This is invalid C#, the Value = x should be Value = "x".
Related issues/PRs
Suggest a fix/enhancement
Generated model should look like the following:
public enum StatusEnum
{
/// <summary>
/// Enum AvailableEnum for available
/// </summary>
[EnumMember(Value = "available")]
AvailableEnum = 1,
/// <summary>
/// Enum PendingEnum for pending
/// </summary>
[EnumMember(Value = "pending")]
PendingEnum = 2,
/// <summary>
/// Enum SoldEnum for sold
/// </summary>
[EnumMember(Value = "sold")]
SoldEnum = 3
}
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
Reproduce the issue with the linked Swagger declaration or gist in editor.swagger.io and generate the aspnetcore server. Start by locating the template or generator path that emits the shown StatusEnum and EnumMember attributes. Done means the generated C# uses quoted enum values and the model is valid C#.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100