如何让 Swagger 列出我的 owin api 控制器

How do I get Swagger to list my owin api controllers

我已经在我的 AspNet 5 WebApi 项目中安装了 Swashbuckle 5.6.0(目前是最新的)。我大摇大摆 UI 出现了,但是我的 api 方法中的 none 被列出了。

我一直胡思乱想,没有成功,然后重新开始。从工作中 API 我刚刚安装了 Swashbuckle 并将其保留在那里以便更容易关联到。

API 托管在 IIS 中,而不是 Express。不过已经试用过了

我该如何调试它?或者更好的是,有人能看出我做错了什么吗?

代码如下;必须删除空行以提高可读性以满足 Whosebug 的要求,抱歉!

启动

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();
        app.UseIdentityServerBearerTokenAuthentication(
            new IdentityServerBearerTokenAuthenticationOptions
            {
                Authority = ConfigurationManager.AppSettings["IdentityServerApplicationUrl"],
                RequiredScopes = new[] {"gallerymanagement"}
            });
        var config = WebApiConfig.Register();
        app.UseWebApi(config);
    }
}

WebApiConfig

public static class WebApiConfig
{
    public static HttpConfiguration Register()
    {
        var config = new HttpConfiguration();
        // Web API routes
        config.MapHttpAttributeRoutes();
        config.Routes.MapHttpRoute(
           name: "DefaultRouting",
           routeTemplate: "api/{controller}/{id}",
           defaults: new { id = RouteParameter.Optional }
       );
        config.EnableCors();
        // clear the supported mediatypes of the xml formatter
        config.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
        config.Formatters.JsonFormatter.SupportedMediaTypes.Add(
            new MediaTypeHeaderValue("application/json-patch+json"));
        var json = config.Formatters.JsonFormatter;
        json.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented;
        json.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
        return config;
    }
}

事件控制器

[EnableCors("*", "*", "GET, POST, DELETE")]
public class EventsController : ApiController
{
    [Route("api/Events/{sub}")]
    public async Task<IHttpActionResult> GetSingleEvent(string sub)
    {
    }

    [Route("api/Events/")]
    public async Task<IHttpActionResult> Get()
    {
    }
}

你想念 init swashbuckle。 看到https://github.com/domaindrivendev/Swashbuckle,还得加

config
.EnableSwagger(c => c.SingleApiVersion("v1", "A title for your API"))
.EnableSwaggerUi(); 

到 WebApiConfig。