我在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()
{
}
}
答案 0 :(得分:0)
你想念init swashbuckle。 请参阅https://github.com/domaindrivendev/Swashbuckle,您必须添加
config
.EnableSwagger(c => c.SingleApiVersion("v1", "A title for your API"))
.EnableSwaggerUi();
到WebApiConfig。