Hi all,
We have some legacy code in our product where we have an enumeration starting at 1:
public enum AccountStateEnum
{
Live = 1,
Trial = 2,
Internal = 3,
Development = 4,
Archived = 5,
Disabled = 6
}
We would like swagger to generate the enum with strings, so we enable the SwaggerConfig setting 'DescribeAllEnumsAsStrings'.
This generates the enum like this:
/// <summary>
/// Gets or Sets AccountState
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
public enum AccountStateEnum
{
/// <summary>
/// Enum Live for "Live"
/// </summary>
[EnumMember(Value = "Live")]
Live,
/// <summary>
/// Enum Trial for "Trial"
/// </summary>
[EnumMember(Value = "Trial")]
Trial,
/// <summary>
/// Enum Internal for "Internal"
/// </summary>
[EnumMember(Value = "Internal")]
Internal,
/// <summary>
/// Enum Development for "Development"
/// </summary>
[EnumMember(Value = "Development")]
Development,
/// <summary>
/// Enum Archived for "Archived"
/// </summary>
[EnumMember(Value = "Archived")]
Archived,
/// <summary>
/// Enum Disabled for "Disabled"
/// </summary>
[EnumMember(Value = "Disabled")]
Disabled
}
Which unfortunately doesn't work for us - as 'Live' needs to equal 1.
If we remove the setting from SwaggerConfig, the enum values are rendered like this:
/// <summary>
/// Gets or Sets AccountState
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
public enum AccountStateEnum
{
/// <summary>
/// Enum NUMBER_1 for 1
/// </summary>
[EnumMember(Value = "1")]
NUMBER_1 = 1,
/// <summary>
/// Enum NUMBER_2 for 2
/// </summary>
[EnumMember(Value = "2")]
NUMBER_2 = 2,
/// <summary>
/// Enum NUMBER_3 for 3
/// </summary>
[EnumMember(Value = "3")]
NUMBER_3 = 3,
/// <summary>
/// Enum NUMBER_4 for 4
/// </summary>
[EnumMember(Value = "4")]
NUMBER_4 = 4,
/// <summary>
/// Enum NUMBER_5 for 5
/// </summary>
[EnumMember(Value = "5")]
NUMBER_5 = 5,
/// <summary>
/// Enum NUMBER_6 for 6
/// </summary>
[EnumMember(Value = "6")]
NUMBER_6 = 6
}
Which has the numbers assigned correctly, however the names are not being included!
Is there a way to get the best of both worlds?
2.3.0
Nothing special about the command line we use!
I have this same issue.
This is my definition
ProofOfOwnership:
type: integer
enum:
- 1
- 2
- 4
x-enumNames:
- Manufacturer's Certificate of Origin
- Title issued in another State/Jurisdiction
- Minnesota Title
This is what I get
/// <summary>
/// Defines ProofOfOwnership
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
public enum ProofOfOwnership
{
/// <summary>
/// Enum _1 for "1"
/// </summary>
[EnumMember(Value = "1")]
_1 = 1,
/// <summary>
/// Enum _2 for "2"
/// </summary>
[EnumMember(Value = "2")]
_2 = 2,
/// <summary>
/// Enum _4 for "4"
/// </summary>
[EnumMember(Value = "4")]
_4 = 3
}
This is what I expect
/// <summary>
/// Defines ProofOfOwnership
/// </summary>
public enum ProofOfOwnership
{
/// <summary>
/// Enum _1 for "1"
/// </summary>
[EnumMember(Value = "1")]
ManufacturersCertificateOfOrigin = 1,
/// <summary>
/// Enum _2 for "2"
/// </summary>
[EnumMember(Value = "2")]
TitleIssuedInAnotherStateJurisdiction = 2,
/// <summary>
/// Enum _4 for "4"
/// </summary>
[EnumMember(Value = "4")]
MinnesotaTitle = 4
}
Same issue for me. I'm using the HttpStatusCode enum.
same issue from me, is it possible to fix soon?
Most helpful comment
I have this same issue.
This is my definition
This is what I get
This is what I expect