最佳答案
试图与 IIS Express 上托管的 Web 应用程序一起设置 swagger。API 是使用 ASPNetCore 构建的。我已经遵循了微软相关帮助页面上关于 Swashuckle 和 ASP.NET Core 的说明。
到目前为止,我已经加载了 swagger 页面,可以看到我定义的 SwaggerDoc 正在加载,但是没有 API。目前我得到以下错误:
“获取未定义的错误./swagger/v1/swagger.json”
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// services.AddDbContext<TodoContext>(opt =>
// opt.UseInMemoryDatabase("TodoList"));
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
// Register the Swagger generator, defining 1 or more Swagger documents
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = "API WSVAP (WebSmartView)", Version = "v1" });
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// Enable middleware to serve generated Swagger as a JSON endpoint.
app.UseSwagger();
// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
// specifying the Swagger JSON endpoint.
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("./swagger/v1/swagger.json", "My API V1");
c.RoutePrefix = string.Empty;
});
app.UseMvc();
}
}