一、swagger使用
1.打开Nuget,搜索安装Swashbuckle.AspNetCore。
2.生成api文档
3.Program.cs 添加如下代码 FreightForwarderApi.xml 替换成你的。
var basePath = AppContext.BaseDirectory;builder.Services.AddSwaggerGen(c => {c.SwaggerDoc("v1", new OpenApiInfo{Version = "v1",Title = "Api"});var xmlPath = Path.Combine(basePath, "FreightForwarderApi.xml");c.IncludeXmlComments(xmlPath, true);//var xmlDomainPath = Path.Combine(basePath, "NET6.Domain.xml");//c.IncludeXmlComments(xmlDomainPath, true);c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme{Description = "Value: Bearer {token}",Name = "Authorization",In = ParameterLocation.Header,Type = SecuritySchemeType.ApiKey,Scheme = "Bearer"});c.AddSecurityRequirement(new OpenApiSecurityRequirement(){{new OpenApiSecurityScheme{Reference = new OpenApiReference{Type = ReferenceType.SecurityScheme,Id = "Bearer"},Scheme = "oauth2",Name = "Bearer",In = ParameterLocation.Header,},new List<string>()}}); });
4.运行后就有了