【发布时间】:2017-11-08 16:45:20
【问题描述】:
我正在使用 Swashbuckle 为我的 .NET 程序集生成 Swagger。我有一个具有非顺序和负值的枚举。像下面这样
[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
};
这些值被重新排序为 0、1、2、3 而不是 0、1、-1、3。
如何让输出 json 包含标题和值,例如:
"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"
}
【问题讨论】:
标签: c# swagger swagger-2.0 swashbuckle swagger-codegen