微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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 举报,一经查实,本站将立刻删除。