最近我已经安装NSwag.AspNetCore
到我的ASP.Net Core 2.1
项目以生成 api 文档,这是我在Startup.cs
文件中的源代码:
public void ConfigureServices(IServiceCollection services)
{
// Add swagger.
services.AddSwagger();
// Construct mvc options.
services.AddMvc(mvcOptions =>
{
////only allow authenticated users
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
.Build();
mvcOptions.Filters.Add(new AuthorizeFilter(policy));
})
.AddJsonOptions(options =>
{
options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
})
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
;
}
public void Configure(IApplicationBuilder app,
IHostingEnvironment env,
ILoggerFactory loggerFactory, IServiceProvider serviceProvider)
{
app.UseSwaggerUi3WithApiExplorer(settings =>
{
settings.GeneratorSettings.DefaultPropertyNameHandling =
PropertyNameHandling.CamelCase;
settings.GeneratorSettings.OperationProcessors.Add(new OperationSecurityScopeProcessor("API Key"));
settings.GeneratorSettings.DocumentProcessors.Add(new SecurityDefinitionAppender("API Key",
new SwaggerSecurityScheme
{
Type = SwaggerSecuritySchemeType.ApiKey,
Name = "Authorization",
Description = "Copy 'Bearer ' + valid JWT token into field",
In = SwaggerSecurityApiKeyLocation.Header
}));
});
app.UseStaticFiles();
// Enable MVC features.
app.UseMvc();
}
起初,我运行了这个项目,它成功了。但在第二次,在我安装NSwag.Annotation
和卸载它之后。当我启动我的应用程序时,端点没有 Swagger UI:<myhost>/swagger
并且状态为:404
任何人都可以帮忙吗?谢谢,