首先添加nuget: Swashbuckle.AspNetCore
services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Version = "v1", Title = "IdentityServer4 & WebApi" }); var basePath = PlatformServices.Default.Application.ApplicationBasePath; var xmlPath = Path.Combine(basePath, "LYM.ApiServices.xml"); c.IncludeXmlComments(xmlPath); } );
app.UseMvc(); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "IdentityServer4 & WebApi"); });

沒有問題,值得注意的是webapi寫法與mvc有區別
自定義名稱需要這樣寫
/// <summary> /// ClientTest測試 /// </summary> /// <param name="value"></param> [HttpPost("ClientTest")] public void ClientTest([FromBody]string value) { }
名稱已經放到上面去了,而在傳統的寫法[RoutePrefix("api/Client")] 被取代了,
如果需要Identityserver4授權需要添加下面的處理 與IdentityServer3一樣
c.AddSecurityDefinition("oauth2", new OAuth2Scheme { Type = "oauth2", Flow = "implicit", AuthorizationUrl = "http://Identityserver4授權地址", Scopes = new Dictionary<string, string> { { "cloudservices", "cloudservices" }, { "clientservices", "clientservices" } } }); c.OperationFilter<SecurityRequirementsOperationFilter>();
