我想在services.AddSwaggerGen中的config.SwaggerDoc中添加两个版本以实现swagger

voase2hg  于 2023-10-18  发布在  其他
关注(0)|答案(1)|浏览(87)

我想在services.AddSwaggerGen中的config.SwaggerDoc中添加两个版本来实现Swagger
例如:

services.AddSwaggerGen(
            config =>
            {
              
                config.SwaggerDoc("v1.1", new OpenApiInfo { Title = "BookingApis V1", Version = "v1.1", Description = "Developed By Demon" });
                config.SwaggerDoc("v2", new OpenApiInfo { Title = "BookingApis V2", Version = "v2", Description = "Developed By Demon" });

})中;
这些设置对于我在Asp.NET和.core6中实现swagger是必要的,这些设置在服务部分的启动中添加。AddSwaggerGen

bxjv4tth

bxjv4tth1#

我发现这个问题你的答案是:

app.UseSwaggerUI(options =>
        { 
            options.SwaggerEndpoint("/swagger/v1/swagger.json", "Booking API V1");
            options.SwaggerEndpoint("/swagger/v2/swagger.json", "Booking  API V2");

            {
                foreach (var description in provider.ApiVersionDescriptions)
                {
                    options.SwaggerEndpoint(
                        $"/swagger/{description.GroupName}/swagger.json",
                        description.GroupName);
                }
            }
        });

相关问题