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

问题描述 投票:0回答:1

我在AspNet 5 WebApi项目中安装了Swashbuckle 5.6.0(目前最新版本)。我得到了昂首阔步的UI,但我的api方法都没有被列出。

我没有成功地四处乱逛,然后开始干净利落。从一个正在运行的API我刚刚安装了Swashbuckle并将其保留在那里以便更容易转换。

API托管在IIS中,而不是Express。尽管如此。

我该如何调试?或者甚至更好,谁能看到我做错了什么?

代码如下;必须删除空行以便于阅读stackoverflow,对不起!

启动

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;
    }
}

EventsController

[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()
    {
    }
}
rest swagger owin
1个回答
0
投票

你想念init swashbuckle。请参阅https://github.com/domaindrivendev/Swashbuckle,您必须添加

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

到WebApiConfig。

© www.soinside.com 2019 - 2024. All rights reserved.