Skip to content

Commit 8544317

Browse files
committed
Added XML Document path for Swagger for summary and remark xml comments
1 parent 79e0b91 commit 8544317

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

WebGYM/WebGYM/Startup.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using System.Linq;
5+
using System.Reflection;
46
using System.Text;
57
using System.Threading.Tasks;
68
using AutoMapper;
@@ -16,6 +18,7 @@
1618
using Microsoft.Extensions.DependencyInjection;
1719
using Microsoft.IdentityModel.Tokens;
1820
using Swashbuckle.AspNetCore.Swagger;
21+
using Swashbuckle.AspNetCore.SwaggerUI;
1922
using WebGYM.Common;
2023
using WebGYM.Concrete;
2124
using WebGYM.Interface;
@@ -43,7 +46,6 @@ public void ConfigureServices(IServiceCollection services)
4346
options.MinimumSameSitePolicy = SameSiteMode.None;
4447
});
4548

46-
4749
#region MyRegion
4850
var connection = Configuration.GetConnectionString("DatabaseConnection");
4951
services.AddDbContext<DatabaseContext>(options => options.UseSqlServer(connection, b => b.UseRowNumberForPaging()));
@@ -183,6 +185,16 @@ public static IServiceCollection AddSwaggerDocumentation(this IServiceCollection
183185
{
184186
c.SwaggerDoc("v1.0", new Info { Title = "Main API v1.0", Version = "v1.0" });
185187

188+
//Locate the XML file being generated by ASP.NET...
189+
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.XML";
190+
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
191+
if (File.Exists(xmlPath))
192+
{
193+
//... and tell Swagger to use those XML comments.
194+
c.IncludeXmlComments(xmlPath);
195+
}
196+
197+
186198
// Swagger 2.+ support
187199
var security = new Dictionary<string, IEnumerable<string>>
188200
{
@@ -209,7 +221,10 @@ public static IApplicationBuilder UseSwaggerDocumentation(this IApplicationBuild
209221
{
210222
c.SwaggerEndpoint("/swagger/v1.0/swagger.json", "Gym Web API v1.0");
211223
c.DocumentTitle = "Title Documentation";
212-
c.DocExpansion(Swashbuckle.AspNetCore.SwaggerUI.DocExpansion.None);
224+
//Reference link : https://stackoverflow.com/questions/22008452/collapse-expand-swagger-response-model-class
225+
//Reference link : https://swagger.io/docs/open-source-tools/swagger-ui/usage/deep-linking/
226+
// c.DocExpansion(Swashbuckle.AspNetCore.SwaggerUI.DocExpansion.None);
227+
// c.DocExpansion(DocExpansion.Full);
213228
// //Reference document: https://docs.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-2.2&tabs=visual-studio
214229
// //To serve the Swagger UI at the app's root (http://localhost:<port>/), set the RoutePrefix property to an empty string:
215230
c.RoutePrefix = string.Empty;

WebGYM/WebGYM/WebGYM.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
<TargetFramework>netcoreapp2.1</TargetFramework>
55
</PropertyGroup>
66

7+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
8+
<NoWarn>1701;1702;1591</NoWarn>
9+
<DocumentationFile>bin\Debug\netcoreapp2.1\WebGYM.xml</DocumentationFile>
10+
<OutputPath>bin\Debug\netcoreapp2.1\</OutputPath>
11+
</PropertyGroup>
12+
713
<ItemGroup>
814
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="6.0.0" />
915
<PackageReference Include="Microsoft.AspNetCore.App" />

0 commit comments

Comments
 (0)