C# 如何从Swashback的XML文档中生成对枚举的描述?
在.NET Core web api项目中,我有一个具有以下枚举的模型:C# 如何从Swashback的XML文档中生成对枚举的描述?,c#,.net-core,swagger,swashbuckle,C#,.net Core,Swagger,Swashbuckle,在.NET Core web api项目中,我有一个具有以下枚举的模型: public enum Industries { Undefined = 0, /// <summary> /// Agriculture, Forestry, Fishing and Hunting /// </summary> AgricultureForestryFishingAndHunting = 1, Mining = 2,
public enum Industries
{
Undefined = 0,
/// <summary>
/// Agriculture, Forestry, Fishing and Hunting
/// </summary>
AgricultureForestryFishingAndHunting = 1,
Mining = 2,
Utilities = 3,
Construction = 4,
/// <summary>
/// Computer and Electronics Manufacturing
/// </summary>
ComputerAndElectronicsManufacturing = 5,
/// <summary>
/// Other Manufacturing
/// </summary>
OtherManufacturing = 6,
Wholesale = 7,
Retail = 8,
/// <summary>
/// Transportation and Warehousing
/// </summary>
TransportationAndWarehousing = 9,
Publishing = 10,
Software = 11,
Telecommunications = 12,
Broadcasting = 13,
/// <summary>
/// Information Services and Data Processing
/// </summary>
InformationServicesAndDataProcessing = 14,
/// <summary>
/// Other Information Industry
/// </summary>
OtherInformationIndustry = 15,
/// <summary>
/// Finance and Insurance
/// </summary>
FinanceAndInsurance = 16,
/// <summary>
/// Real Estate, Rental and Leasing
/// </summary>
RealEstateRentalAndLeasing = 17,
/// <summary>
/// College, University, and Adult Education
/// </summary>
CollegeUniversityAndAdultEducation = 18,
/// <summary>
/// Primary/Secondary (K-12) Education
/// </summary>
PrimarySecondaryK12Education = 19,
/// <summary>
/// Other Education Industry
/// </summary>
OtherEducationIndustry = 20,
/// <summary>
/// Health Care and Social Assistance
/// </summary>
HealthCareAndSocialAssistance = 21,
/// <summary>
/// Arts, Entertainment, and Recreation
/// </summary>
ArtsEntertainmentAndRecreation = 22,
/// <summary>
/// Hotel and Food Services
/// </summary>
HotelAndFoodServices = 23,
/// <summary>
/// Government and Public Administration
/// </summary>
GovernmentAndPublicAdministration = 24,
/// <summary>
/// Legal Services
/// </summary>
LegalServices = 25,
/// <summary>
/// Scientific or Technical Services
/// </summary>
ScientificorTechnicalServices = 26,
Homemaker = 27,
Military = 28,
Religious = 29,
/// <summary>
/// Other Industry
/// </summary>
OtherIndustry = 30
}
运行此命令并查看swagger.json
文档时,我根本看不到枚举值的XML注释,只看到以下值:
"definitions": {
...
"MySolution.Common.Models.Industries": {
"enum": [
"undefined",
"agricultureForestryFishingAndHunting",
"mining",
"utilities",
"construction",
"computerAndElectronicsManufacturing",
"otherManufacturing",
"wholesale",
"retail",
"transportationAndWarehousing",
"publishing",
"software",
"telecommunications",
"broadcasting",
"informationServicesAndDataProcessing",
"otherInformationIndustry",
"financeAndInsurance",
"realEstateRentalAndLeasing",
"collegeUniversityAndAdultEducation",
"primarySecondaryK12Education",
"otherEducationIndustry",
"healthCareAndSocialAssistance",
"artsEntertainmentAndRecreation",
"hotelAndFoodServices",
"governmentAndPublicAdministration",
"legalServices",
"scientificorTechnicalServices",
"homemaker",
"military",
"religious",
"otherIndustry"],
"type": "string"
}
}
我错过了什么使这项工作?我使用的是Swashback的v2.5.0版本,它看起来是最新和最好的版本。OAS(OpenAPI规范)不支持对枚举值的注释: 5.5.1.1。有效值 此关键字的值必须是数组。此数组必须至少有一个 至少有一个元素。数组中的元素必须是唯一的 数组中的元素可以是任何类型,包括null
includexmlcompresents让我感到一阵痛苦,我找到的最佳解决方案是在项目中的所有文件夹上递归加载所有.xml文件。好了,我的xml文件已经加载,就我所知,只是枚举信息没有通过。。。。这可能是一个Bug或者OAS不支持吗?哇,这是。。。奇怪的认真地为什么有人认为我们不需要记录枚举值的含义和用途?这太疯狂了。不过有一个建议要加上它:@JeremyHolovacs不要对这个建议抱太大的希望,它是在2015年4月29日创建的,即使它今天获得批准,它也需要一段时间才能被大摇大摆的用户界面实现并包含在大摇大摆的Buckle中
"definitions": {
...
"MySolution.Common.Models.Industries": {
"enum": [
"undefined",
"agricultureForestryFishingAndHunting",
"mining",
"utilities",
"construction",
"computerAndElectronicsManufacturing",
"otherManufacturing",
"wholesale",
"retail",
"transportationAndWarehousing",
"publishing",
"software",
"telecommunications",
"broadcasting",
"informationServicesAndDataProcessing",
"otherInformationIndustry",
"financeAndInsurance",
"realEstateRentalAndLeasing",
"collegeUniversityAndAdultEducation",
"primarySecondaryK12Education",
"otherEducationIndustry",
"healthCareAndSocialAssistance",
"artsEntertainmentAndRecreation",
"hotelAndFoodServices",
"governmentAndPublicAdministration",
"legalServices",
"scientificorTechnicalServices",
"homemaker",
"military",
"religious",
"otherIndustry"],
"type": "string"
}
}