I’m using Swashbuckle to generate a Swagger for my .NET assembly. I have an enum with non-sequential and negative values. Like the following
[JsonConverter(typeof(StringEnumConverter))]
public enum ShiftDayOffRule
{
/// <summary>
/// Shift has no day off rule.
/// </summary>
None = 0, // DayOffNotRequired
/// <summary>
/// If shift with this rule is scheduled then next day must be a day off.
/// </summary>
OffAfter = 1, // DayOffAfter <=> next is off
/// <summary>
/// If shift with this rule is scheduled then previous day must be a day off.
/// </summary>
OffBefore = -1, // DayOffBefore <=> previous is off
/// <summary>
/// If shift with this rule is scheduled then next day must be a work day.
/// </summary>
InAfter = 3 // DayInAfter <=> next cannot be off
};
The values are getting reordered to 0, 1, 2, 3 instead of 0, 1, -1, 3.
How do I get the output json to include title and value like:
"dayoffRule": {
"description": "Day off rule for the shift. ScheduleData.Enums.ShiftDayOffRule",
"enum": [
{"title": "None", "value": 0},
{"title": "OffAfter", "value": 1},
{"title": "InAfter", "value": 3},
{"title": "OffBefore", "value": -1}
],
"type": "string"
}