Skip to content
This repository was archived by the owner on Apr 17, 2025. It is now read-only.

Commit c4145c3

Browse files
committed
Aggiunta configurazione Swagger WebApp
1 parent a3b319e commit c4145c3

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# SwaggerUI configuration
2+
3+
4+
## Registering services at Startup
5+
6+
```csharp
7+
public Startup(IConfiguration configuration)
8+
{
9+
Configuration = configuration;
10+
}
11+
12+
//OMISSIS
13+
14+
public void Configure(WebApplication app)
15+
{
16+
app.AddUseSwaggerUI("My Web Api v1");
17+
}
18+
```

src/NET6CustomLibrary/GlobalUsings.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
global using Microsoft.AspNetCore.Identity.UI.Services;
1818
global using Microsoft.AspNetCore.Routing;
1919
global using Microsoft.EntityFrameworkCore;
20-
global using Microsoft.EntityFrameworkCore.ChangeTracking;
21-
global using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
2220
global using Microsoft.Extensions.Configuration;
2321
global using Microsoft.Extensions.DependencyInjection;
2422
global using Microsoft.Extensions.Diagnostics.HealthChecks;
@@ -38,6 +36,7 @@
3836
global using NET6CustomLibrary.EFCore.Infrastructure.Repository;
3937
global using NET6CustomLibrary.MailKit.Options;
4038
global using NET6CustomLibrary.MailKit.Services;
39+
global using NET6CustomLibrary.MultiLanguage;
4140
global using NET6CustomLibrary.RabbitMQ.Abstractions;
4241
global using NET6CustomLibrary.Serilog.Models;
4342
global using NET6CustomLibrary.Serilog.Services;

src/NET6CustomLibrary/NET6CustomLibrary.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
</PackageReference>
4141
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="7.0.0" />
4242
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.5.0" />
43+
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.5.0" />
4344
<PackageReference Include="System.Text.Json" Version="7.0.2" />
4445
</ItemGroup>
4546

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
namespace NET6CustomLibrary.Swagger;
2+
3+
public static class SwaggerOptions
4+
{
5+
public static WebApplication AddUseSwaggerUI(this WebApplication app, string title)
6+
{
7+
app.UseSwagger();
8+
app.UseSwaggerUI(options =>
9+
{
10+
options.RoutePrefix = string.Empty;
11+
options.SwaggerEndpoint("/swagger/v1/swagger.json", $"{title}");
12+
});
13+
14+
return app;
15+
}
16+
17+
public static OpenApiInfo AddOptionalOpenApiInfo(this OpenApiInfo openApiInfo, string name, string email, string siteUrl,
18+
string nameLicense = "MIT License", string urlLicense = "https://opensource.org/licenses/MIT")
19+
{
20+
openApiInfo.Contact = new OpenApiContact
21+
{
22+
Name = $"{name}",
23+
Email = $"{email}",
24+
Url = new Uri($"{siteUrl}"),
25+
};
26+
27+
openApiInfo.License = new OpenApiLicense
28+
{
29+
Name = $"{nameLicense}",
30+
Url = new Uri($"{urlLicense}"),
31+
};
32+
33+
return openApiInfo;
34+
}
35+
}

0 commit comments

Comments
 (0)