在你想到它之前,this是不一样的。
我认为这应该是不言而喻的。我想在Swagger文档中包含类描述。我的Swagger
配置如下所示:
config.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "My Api Name");
c.OperationFilter<AddAuthorizationHeaderParameterOperationFilter>();
c.IncludeXmlComments(GetXmlCommentsPath());
}).EnableSwaggerUi(c => { });
MyAwesomeController
看起来像这样:
/// <summary>
/// Controller description (is included by Swashbuckle)
/// </summary>
public class MyAwesomeController : ApiController
{
/// <summary>
/// Method description (is included by Swashbuckle)
/// </summary>
public IHttpActionResult Get()
{
return Ok("hello... from the other side");
}
public IHttpActionResult Post([FromBody]MyAwesomeModel model)
{
return Ok("hello... from the other side");
}
}
我的MyAwesomeModel
是这样的:
/// <summary>
/// **I would like this to be included in the Swagger description of the parameter**
/// </summary>
public class MyAwesomeModel
{
/// <summary>
/// **I would like this to be included in the Swagger description of the parameter**
/// </summary>
public string MyProperty { get; set; }
}
有没有可能在不雇佣斯基特的情况下实现?
发布于 2016-09-20 16:20:06
嗯..。所以也许如果其他人也遇到这种情况。
基本上,我找到了一种可以做到这一点的方法,并且我意识到为什么它不是默认的。不确定这是否是最好的方法,但它开始了。
在我的解决方案中,POCOs位于一个独立于实际API的项目中,因此没有包括MyAwesomeModel
的注释描述,因为没有为类和属性生成XML节点。因此,在POCOs所在的单独项目中,我修改了属性以生成XML。
Swashbuckle
查找它的任何路径。我在项目属性中使用了Post-build event command line
;copy "$(SolutionDir)MyAwesomeProjectWithPocos\bin\MyAwesomeProjectWithPocos.xml" "$(ProjectDir)\bin\MyAwesomeProjectWithPocos.xml"
SwaggerConfig
修改为也包含此XML 也就是说。
config.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "My Api Name");
c.OperationFilter<AddAuthorizationHeaderParameterOperationFilter>();
c.IncludeXmlComments(GetXmlCommentsPath());
c.IncludeXmlComments(GetXmlCommentsPathForModels());
}).EnableSwaggerUi(c => { });
现在,在Swagger页面上,如果我从Model Schema
切换到Model
,我现在可以读取整个模型和属性描述。
当然,不需要复制XML文件,只需在步骤#3 GetXmlCommentsPathForModels());
中指向正确的位置,但这是我的选择。
发布于 2016-09-20 04:43:58
如果您已经将下面的语句
c.IncludeXmlComments(GetXmlCommentsPath());
您是否可以检查xml注释路径方法是否返回放置Project xml文档文件的XML文件的路径?
https://stackoverflow.com/questions/39576189
复制相似问题