为什么在 owin 实施后,swagger 不起作用?
Why, after owin implementation, swagger not work?
我正在使用 Microsoft Web API 2 和 SwaggerUi 开发 RESTful 网络服务。
我已经删除了默认值 Global.asax 并且我已经使用 OWIN 配置了我的 Web API。这是我的 Startup.cs 代码:
public void Configuration(IAppBuilder app)
{
HttpConfiguration config = new HttpConfiguration();
WebApiConfig.Register(config);
config.MessageHandlers.Add(new JWTAuthenticationHandler() { StopPipelineHandling = true });
config.Filters.Add(new MyActionFilter());
SwaggerConfig.Register();
app.UseWebApi(config);
}
这是我的 SwaggerConfig.cs 代码:
GlobalConfiguration.Configuration
.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "MyNamespace.WebApi");
})
.EnableSwaggerUi(c =>
{});
此操作后我无法查看 swagger 上的操作,如下图所示:
拜托,你能帮帮我吗?
非常感谢
我已决定更改:
Startup.cs
public void Configuration(IAppBuilder app)
{
HttpConfiguration config = new HttpConfiguration();
// Swagger
SwaggerConfig.Register(config);
// Authentication token
ConfigureOAuth(app);
// SignalR configuration
ConfigureSignalR(app);
// Register routes
WebApiConfig.Register(config);
// Allow cross-domain requests
app.UseCors(CorsOptions.AllowAll);
app.UseWebApi(config);
}
SwaggerConfig.cs
using Swashbuckle.Application;
using System.Web.Http;
namespace Name.API
{
public class SwaggerConfig
{
public static void Register(HttpConfiguration config)
{
config.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "Name.API");
})
.EnableSwaggerUi(c =>
{
});
}
}
}
我在 https://github.com/domaindrivendev/Swashbuckle/issues/196
上找到了解决方案
我在 Owin + Swashbuckle 集成方面遇到了很多问题。上面给出的解决方案是不完整的,我不得不想出很多其他的东西来确保兼容性。我的最终结果在这个 repo 中开源,作为任何需要它的人的模板!
我正在使用 Microsoft Web API 2 和 SwaggerUi 开发 RESTful 网络服务。
我已经删除了默认值 Global.asax 并且我已经使用 OWIN 配置了我的 Web API。这是我的 Startup.cs 代码:
public void Configuration(IAppBuilder app)
{
HttpConfiguration config = new HttpConfiguration();
WebApiConfig.Register(config);
config.MessageHandlers.Add(new JWTAuthenticationHandler() { StopPipelineHandling = true });
config.Filters.Add(new MyActionFilter());
SwaggerConfig.Register();
app.UseWebApi(config);
}
这是我的 SwaggerConfig.cs 代码:
GlobalConfiguration.Configuration
.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "MyNamespace.WebApi");
})
.EnableSwaggerUi(c =>
{});
此操作后我无法查看 swagger 上的操作,如下图所示:
拜托,你能帮帮我吗?
非常感谢
我已决定更改:
Startup.cs
public void Configuration(IAppBuilder app)
{
HttpConfiguration config = new HttpConfiguration();
// Swagger
SwaggerConfig.Register(config);
// Authentication token
ConfigureOAuth(app);
// SignalR configuration
ConfigureSignalR(app);
// Register routes
WebApiConfig.Register(config);
// Allow cross-domain requests
app.UseCors(CorsOptions.AllowAll);
app.UseWebApi(config);
}
SwaggerConfig.cs
using Swashbuckle.Application;
using System.Web.Http;
namespace Name.API
{
public class SwaggerConfig
{
public static void Register(HttpConfiguration config)
{
config.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "Name.API");
})
.EnableSwaggerUi(c =>
{
});
}
}
}
我在 https://github.com/domaindrivendev/Swashbuckle/issues/196
上找到了解决方案我在 Owin + Swashbuckle 集成方面遇到了很多问题。上面给出的解决方案是不完整的,我不得不想出很多其他的东西来确保兼容性。我的最终结果在这个 repo 中开源,作为任何需要它的人的模板!