【发布时间】:2016-11-09 07:37:18
【问题描述】:
我是 Swashbuckl 或 Swagger 的新手,但我创建了一个 Web API,需要使用来自我的客户端的 Swagger 创建文档。我已经创建了,但他们需要将 API 版本详细信息显示在 Swageer UI 中,我不太确定如何实现。
这是我的代码:
public class SwaggerConfig
{
public static void Register()
{
var thisAssembly = typeof(SwaggerConfig).Assembly;
GlobalConfiguration.Configuration
.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "Demo Api");
c.IncludeXmlComments(string.Format(@"{0}\bin\WebApi.XML",
System.AppDomain.CurrentDomain.BaseDirectory));
})
.EnableSwaggerUi();
}
}
控制器示例:
/// <summary>
/// Get the Next IdKey
/// </summary>
/// <remarks>Get the Next IdKey from Dettagli Table</remarks>
/// <response code="404">Not found</response>
/// <response code="500">Internal Server Error</response>
[HttpGet]
public int GetNextIdDettagli()
{
try
{
DettagliRepo repo = new DettagliRepo();
return repo.GetNextIdDettagli();
}
catch (Exception ex)
{
throw (ex);
}
}
这就是所有控制器操作的完成方式。
这是我的 Swagger UI 的输出:
这是我的客户端的预期输出,标记为 1,2 和 3:
我可以从屏幕截图中了解到他们希望显示 API 描述、标题和其他信息,但我不知道如何显示。请帮助我或建议我如何实现那部分。提前致谢。
更新
我已经通过Following link 实现了 1 和 2
使用以下代码:
.EnableSwagger(c =>
{
c.RootUrl(req => GetRootUrlFromAppConfig());
c.Schemes(new[] { "http", "https" });
c.SingleApiVersion("v1", "Swashbuckle.Dummy")
.Description("A sample API for testing and prototyping Swashbuckle features")
.TermsOfService("Some terms")
.Contact(cc => cc
.Name("Some contact")
.Url("http://tempuri.org/contact")
.Email("some.contact@tempuri.org"))
.License(lc => lc
.Name("Some License")
.Url("http://tempuri.org/license"));
});
但我仍然需要关于第 3 点的帮助。谢谢。
【问题讨论】:
标签: c# asp.net-mvc api swagger swashbuckle