控制器的ASP .NET Boilerplate Swagger XML文档不可见

问题描述

我使用asp样板模板创建了一个Angular SPA项目,并根据this issue中的建议为示例功能的控制器实现添加摘要

/// <summary>
/// This is my sample function
/// </summary>
/// <returns></returns>
public Task SummaryTestMethod()
{
    return Task.CompletedTask;
}

但是,昂首阔步的UI似乎没有记录我的言论。到目前为止,我还没有更改代码中的任何其他部分。认配置是否不应包含这些备注?可能是什么问题?

解决方法

您可以按照以下步骤操作:

1。启用XML文档的创建。在 Solution Explorer 中,右键单击该项目,然后单击 Properties 。点击构建标签,然后导航至输出。确保已选中 XML文档文件选项。您可以保留默认文件路径:

enter image description here

2。您需要对我们的Startup.cs文件进行一些更改,以使您大摇大摆地使用这些注释:

services.AddSwaggerGen(c =>
{
    //1.locate the xml file being generated
    //if you choose the default file path in the first step,//the file name is SolutionName.xml
    //the file path is the project path
    var xmlFile = $"{Assembly.GetEntryAssembly().GetName().Name}.XML";
    var xmlPath = Path.Combine(AppContext.BaseDirectory,xmlFile);

    //2.tell swagger to use those xml comments
    c.IncludeXmlComments(xmlPath);
    //...
}

结果:

enter image description here

参考:

https://docs.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-3.1&tabs=visual-studio#xml-comments

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...