Skip to content

Commit d82d78d

Browse files
🔨 Implement swagger configuration
1 parent 456cff2 commit d82d78d

File tree

1 file changed

+39
-0
lines changed
  • sample/EntityFrameworkCore.DataEncryption.Sample

1 file changed

+39
-0
lines changed

sample/EntityFrameworkCore.DataEncryption.Sample/Program.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Reflection;
12
using System.Text.Json.Serialization;
23
using EntityFrameworkCore.DataEncryption.Sample.Context;
34
using Microsoft.EntityFrameworkCore;
@@ -14,13 +15,51 @@
1415
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection"));
1516
});
1617

18+
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
19+
builder.Services.AddEndpointsApiExplorer();
20+
builder.Services.AddSwaggerGen(options =>
21+
{
22+
options.SwaggerDoc("DataEncryption", new Microsoft.OpenApi.Models.OpenApiInfo()
23+
{
24+
Title = "EntityFrameworkCore.DataEncryption",
25+
Version = "1.0.0",
26+
Description = "This package is a plugin that adds Data Encryption support to EntityFrameworkCore.",
27+
Contact = new Microsoft.OpenApi.Models.OpenApiContact()
28+
{
29+
Email = "furkan.dvlp@gmail.com",
30+
Url = new Uri("https://github.com/furkandeveloper/EntityFrameworkCore.DataEncryption")
31+
}
32+
});
33+
var docFile = $"{Assembly.GetEntryAssembly()?.GetName().Name}.xml";
34+
var filePath = Path.Combine(AppContext.BaseDirectory, docFile);
35+
36+
if (File.Exists((filePath)))
37+
{
38+
options.IncludeXmlComments(filePath);
39+
}
40+
options.DescribeAllParametersInCamelCase();
41+
});
42+
1743
var app = builder.Build();
1844

1945
if (app.Environment.IsDevelopment())
2046
{
2147
app.UseDeveloperExceptionPage();
2248
}
2349

50+
app.UseRouting();
51+
52+
app.UseSwagger();
53+
54+
app.UseSwaggerUI(options =>
55+
{
56+
options.EnableDeepLinking();
57+
options.ShowExtensions();
58+
options.DisplayRequestDuration();
59+
options.DocExpansion(Swashbuckle.AspNetCore.SwaggerUI.DocExpansion.None);
60+
options.RoutePrefix = "api-docs";
61+
options.SwaggerEndpoint("/swagger/DataEncryption/swagger.json", "EasyProfilerSwagger");
62+
});
2463
app.MapControllers();
2564

2665
app.MapDefaultControllerRoute();

0 commit comments

Comments
 (0)