gpt4 book ai didi

c# - 我可以使用 Swashbuckle 从 Blazor 项目 c# 生成 Swagger UI

转载 作者:行者123 更新时间:2023-12-04 02:43:47 24 4
gpt4 key购买 nike

我可以使用 Swashbuckle 通过 Blazor C# 从项目生成 Swagger UI我知道 swaschbuckle 需要 MVC,并且你不能在同一个项目中同时拥有它们。但是有什么办法可以解决吗。

最佳答案

我已经通过为 W ASP.Net 核心 3.0 应用程序使用 Balzor 模板解决了这个问题。并遵循本指南:Getting started with swashbuckle ASP.Net Core 3.0

自 4.0.1 版启动失败以来,我一直使用 Swashbuckle 的预发布版 5.0.0-rc3。

我为面临同样问题的人创办的公司:

public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{

services.AddControllers();
// Register the Swagger generator, defining 1 or more Swagger documents
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
});
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddScoped<AuthenticationStateProvider, RevalidatingIdentityAuthenticationStateProvider<IdentityUser>>();
services.AddSingleton<WeatherForecastService>();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

// 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");
});

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
}
}

关于c# - 我可以使用 Swashbuckle 从 Blazor 项目 c# 生成 Swagger UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58084615/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com