7
7
using Microsoft . Extensions . Configuration ;
8
8
using Microsoft . Extensions . DependencyInjection ;
9
9
using Microsoft . Extensions . Hosting ;
10
+ using Microsoft . OpenApi . Models ;
10
11
using Newtonsoft . Json . Converters ;
12
+ using System ;
13
+ using System . IO ;
14
+ using System . Linq ;
15
+ using System . Reflection ;
11
16
12
17
namespace jQueryDatatableServerSideNetCore
13
18
{
@@ -38,6 +43,17 @@ public void ConfigureServices(IServiceCollection services)
38
43
services . AddRazorPages ( ) ;
39
44
40
45
services . AddScoped < IExportService , ExportService > ( ) ;
46
+
47
+ // Register the Swagger generator, defining 1 or more Swagger documents
48
+ services . AddSwaggerGen ( c =>
49
+ {
50
+ c . SwaggerDoc ( "v1" , new OpenApiInfo { Title = "jQueryDatatableServerSideNetCore" , Version = "v1" } ) ;
51
+ c . ResolveConflictingActions ( apiDescriptions => apiDescriptions . FirstOrDefault ( ) ) ;
52
+
53
+ var xmlFile = $ "{ Assembly . GetExecutingAssembly ( ) . GetName ( ) . Name } .xml";
54
+ var xmlPath = Path . Combine ( AppContext . BaseDirectory , xmlFile ) ;
55
+ c . IncludeXmlComments ( xmlPath ) ;
56
+ } ) ;
41
57
}
42
58
43
59
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -57,6 +73,14 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
57
73
app . UseHttpsRedirection ( ) ;
58
74
app . UseStaticFiles ( ) ;
59
75
76
+ // Enable middleware to serve generated Swagger as a JSON endpoint.
77
+ app . UseSwagger ( ) ;
78
+ app . UseSwaggerUI ( c =>
79
+ {
80
+ c . RoutePrefix = "docs" ;
81
+ c . SwaggerEndpoint ( "/swagger/v1/swagger.json" , "jQueryDatatableServerSideNetCore Docs v1" ) ;
82
+ } ) ;
83
+
60
84
app . UseRouting ( ) ;
61
85
62
86
app . UseAuthentication ( ) ;
@@ -66,7 +90,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
66
90
{
67
91
endpoints . MapControllerRoute (
68
92
name : "default" ,
69
- pattern : "{controller=Home }/{action=Index}/{id?}" ) ;
93
+ pattern : "{controller=TestRegisters }/{action=Index}/{id?}" ) ;
70
94
endpoints . MapRazorPages ( ) ;
71
95
} ) ;
72
96
}
0 commit comments