swagger-ui中默认为api版本值

问题描述 投票:0回答:1

[我在asp.core wep-api项目中配置了摇摇欲坠,它的工作正常。现在,当swagger-ui出现如下图时,我正在寻找解决方案

https://imgur.com/a/K7QTKCu

api版本部分应根据代码端的配置自动填充。

        services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("v1", new Info
            {
                Version = "v1",
                Title = "My API",
                Contact = new Contact
                {
                    Name = "My Api",
                    Url = "https://109.com/"
                }
            });
            var security = new Dictionary<string, IEnumerable<string>>
            {
                {"Bearer", new string[] { }},
            };
            c.AddSecurityDefinition("Bearer", new ApiKeyScheme
            {
                Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
                Name = "Authorization",
                In = "header",
                Type = "apiKey"
            });
            c.AddSecurityRequirement(security);
        });
c# asp.net-core swagger-ui
1个回答
0
投票

您需要安装Microsoft.AspNetCore.Mvc.VersioningMicrosoft.AspNetCore.Mvc.Versioning.ApiExplorer软件包才能在Swagger中启用API版本控制。

您可以在here处查看其他详细信息。

ConfigureServices方法中,将版本控制方案定义为

 services.AddVersionedApiExplorer(o =>
 {
      o.GroupNameFormat = "'v'VVV";
      o.SubstituteApiVersionInUrl = true;
 });
 services.AddApiVersioning(config =>
 {
     config.DefaultApiVersion = new ApiVersion(1, 0);
     config.AssumeDefaultVersionWhenUnspecified = true;
     config.ReportApiVersions = true;
 });
© www.soinside.com 2019 - 2024. All rights reserved.