From 962eed37a9cc4e1b37223eba64bf0ec13cfd3e54 Mon Sep 17 00:00:00 2001 From: bicijinlian Date: Mon, 16 Nov 2020 21:41:29 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E5=8D=95Swagger?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AccessStudy.WebApi/Controllers/StudentController.cs | 3 +++ AccessStudy.WebApi/Startup.cs | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/AccessStudy.WebApi/Controllers/StudentController.cs b/AccessStudy.WebApi/Controllers/StudentController.cs index e1cead7..2f9fb97 100644 --- a/AccessStudy.WebApi/Controllers/StudentController.cs +++ b/AccessStudy.WebApi/Controllers/StudentController.cs @@ -74,6 +74,9 @@ namespace AccessStudy.WebApi.Controllers /// 请求例子: /// GET /api/Student/GetByName?studentName=王高峰 /// + /// + /// GET /api/Student/GetByName?studentName=王高峰 + /// /// [HttpGet] public ResultBase GetByName(string studentName) diff --git a/AccessStudy.WebApi/Startup.cs b/AccessStudy.WebApi/Startup.cs index 3213654..605a1e7 100644 --- a/AccessStudy.WebApi/Startup.cs +++ b/AccessStudy.WebApi/Startup.cs @@ -34,6 +34,7 @@ namespace AccessStudy.WebApi //services.AddScoped(); services.AddScoped(); + #region Swagger services.AddSwaggerGen(option => { option.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo() { Title = "API", Version = "v1" }); @@ -41,13 +42,21 @@ namespace AccessStudy.WebApi // Set the comments path for the Swagger JSON and UI. var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = System.IO.Path.Combine(AppContext.BaseDirectory, xmlFile); - option.IncludeXmlComments(xmlPath); + + //不显示控制器注释 + //option.IncludeXmlComments(xmlPath); + + //显示控制器注释 + option.IncludeXmlComments(xmlPath, true); }); //services.ConfigureSwaggerGen(option => //{ //}); + #endregion + + } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.