ASP.NET 5中指定的OpenApi/Swagger版本在哪里

问题描述

我已经使用 Blazor Wasm 托管应用程序配置了 swagger,但出现以下错误:

无法呈现此定义。提供的定义未指定有效的版本字段。我已经包含了该消息的屏幕截图以及配置 swagger 的代码。

enter image description here

//

            services.AddMvc()
            .AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1",new OpenApiInfo {Title = "Workflows API",Version = "v1"});
            });
// Configure()
            app.UseSwagger();
        app.UseSwaggerUI(c =>
        {
            c.SwaggerEndpoint("/swagger/v1/swagger.json","Workflows API v1");
        });

******************** 编辑 ********************

当我生成一个新的 Web API 项目时,这似乎在临时项目中有效。当我将这些相同的行添加到我的项目时,问题仍然存在:

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
    services.AddControllers();
    services.AddSwaggerGen(c =>
    {
        c.SwaggerDoc("v1",new OpenApiInfo {Title = "SwaggerTest",Version = "v1"});
    });
}

// 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.UseSwagger();
        app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json","SwaggerTest v1"));
    }

    app.UseHttpsRedirection();

    app.UseRouting();

    app.UseAuthorization();

    app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...