如果您使用的是SwashBuckle4.0.x和ASP.NET Core2.x,您可能有类似的功能,它也可以通过包含Swashbuckle.aspnetcore.Annotations的NuGet包来工作。
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Swashbuckle.AspNetCore.Annotations;
namespace MyExample.Controllers
{
/// <summary>
/// Example of a .NET Core controller based on the controller name
/// api/[controller] on ValuesController becomes api/values
/// endpoint: "/Values" from [controller] and name of controller , which is "ValuesController"
/// </summary>
[Route("[controller]")]
[ApiController]
[SwaggerTag("This is an example controller generated by ASP.NET Core 2.x")]
public class ValuesController : ControllerBase
{
...
}
然后ConfigureServices方法中的Startup.cs swagger代码如下所示(编辑为包含Iain Carlin的贡献,以包含控制器头注释):
services.AddSwaggerGen(c =>
{
// Set Title and version
c.SwaggerDoc("v1", new Info { Title = "My Example API", Version = "v1", Description = "The API for my application" });
// Set the comments path for the Swagger JSON and UI.
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
// pick comments from classes, including controller summary comments
c.IncludeXmlComments(xmlPath, includeControllerXmlComments: true);
// _OR_ enable the annotations on Controller classes [SwaggerTag], if no class comments present
c.EnableAnnotations();
});
然后我的控制器会被装饰
知道如何正确设置控制器描述吗? 谢谢,马里奥
我正试图提供格式化的描述给一个在大摇大摆的控制器。但是,我找不到任何可以启用它的注释。当前看起来如下所示: 然而,我想提供有意义的描述。不推荐使用带有的参数。
.NET核心和ASP.NET核心到底有什么区别?
我在控制器中编写了几个操作方法,以测试ASP.NET核心中同步和异步控制器操作之间的差异: 正如您所看到的,每秒的请求没有太大差异--我希望异步endpoint每秒处理更多的请求。我是不是漏掉了什么?
ASP.NETCore支持一个新的配置系统,如下所示:https://docs.asp.net/en/latest/fundamentals/configuration.html 也支持这种模式吗?NET核心控制台应用程序? 如果不是,什么是替代以前的和模型?