C# 虚张声势的抽象类文档

C# 虚张声势的抽象类文档,c#,asp.net-web-api,asp.net-core,swagger,swashbuckle,C#,Asp.net Web Api,Asp.net Core,Swagger,Swashbuckle,我有具有以下属性的Web API请求模型: public List<Feature> Features { get; set; } 显然,Swashback只识别特性属性,并相应地生成文档。如何明确声明Feature类的可能实现,以便Swashback生成正确的文档?我是否可以使用一些属性,例如: [SwaggerResponseType(typeof(ImageFeature))] [SwaggerResponseType(typeof(AnotherFeature))] pub

我有具有以下属性的Web API请求模型:

public List<Feature> Features { get; set; }
显然,Swashback只识别
特性
属性,并相应地生成文档。如何明确声明
Feature
类的可能实现,以便Swashback生成正确的文档?我是否可以使用一些属性,例如:

[SwaggerResponseType(typeof(ImageFeature))]
[SwaggerResponseType(typeof(AnotherFeature))]
public abstract class Feature
看看这个:

下面是控制器背后的代码:

使用System.Web.Http;
命名空间Swagger_Test.Controllers
{
公共抽象类特征
{
///我们都需要一个头衔
公共字符串标题{get;set;}
}
公共类ImageFeature:Feature
{
///这是你的图片URL
公共字符串ImageUrl{get;set;}
}
公共类InheritanceTestController:ApicController
{
公共ImageFeature获取([FromUri]ImageFeature ImageFeature)
{
返回图像特征;
}
公共图像功能发布(图像功能图像功能)
{
返回图像特征;
}
}
}

没有特定于请求模型的选项。可能的选项是编写操作筛选器

这是伪代码

    public class RequestModelExtentionOperator: IOperationFilter    
        {                 
    public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
    {
        if (operation.operationId == "Controller_ActionName")  // controller and action name
        {
           var refSchema = schemaRegistry.GetOrRegister(typeof(List<ImageFeature>));
                //here you can create a new Parameter of type Array
var param=new Parameter 
                    {
                        name = "Features",
                        @in = "formData",
                        required = true,
                        type = "array"
                    };
            param.PopulateFrom(schema);
operation.parameters = new[]{ param };
        }
    }            
            }
    }
公共类requestModelExtensionOperator:IOperationFilter
{                 
public void Apply(操作,SchemaRegistry SchemaRegistry,apisdescription apisdescription)
{
if(operation.operationId==“Controller\u ActionName”)//控制器和操作名称
{
var refSchema=schemaRegistry.GetOrRegister(typeof(List));
//在这里,您可以创建类型为Array的新参数
var param=新参数
{
name=“Features”,
@in=“formData”,
必需=真,
type=“数组”
};
参数PopulateFrom(模式);
operation.parameters=new[]{param};
}
}            
}
}
然后我们可以设置OperationFilter

httpConfiguration
     .EnableSwagger(c => c.SingleApiVersion("v1", "A title for your API"))
         {
             c.OperationFilter<RequestModelExtentionOperator>();
         });
httpConfiguration
.EnableSwagger(c=>c.SingleApiVersion(“v1”,“您的API的标题”))
{
c、 操作过滤器();
});
希望它有助于

可能的重复:我使用这种方法-
    public class RequestModelExtentionOperator: IOperationFilter    
        {                 
    public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
    {
        if (operation.operationId == "Controller_ActionName")  // controller and action name
        {
           var refSchema = schemaRegistry.GetOrRegister(typeof(List<ImageFeature>));
                //here you can create a new Parameter of type Array
var param=new Parameter 
                    {
                        name = "Features",
                        @in = "formData",
                        required = true,
                        type = "array"
                    };
            param.PopulateFrom(schema);
operation.parameters = new[]{ param };
        }
    }            
            }
    }
httpConfiguration
     .EnableSwagger(c => c.SingleApiVersion("v1", "A title for your API"))
         {
             c.OperationFilter<RequestModelExtentionOperator>();
         });