feat: add swagger ui to create API documentation automatically

This commit is contained in:
2025-05-06 10:05:38 +02:00
parent 0e14821cec
commit 33f8e80f62
3 changed files with 77 additions and 68 deletions

View File

@@ -1,11 +1,9 @@
using Microsoft.AspNetCore.Mvc;
using System.Linq.Expressions;
using System.Reflection.Metadata;
using WebApp.Data;
using WebApp.Entities;
namespace WebApp.Controllers.Api
{
namespace WebApp.Controllers.Api;
[ApiController]
[Route("api/events")]
public class EventsApiController : ControllerBase
@@ -86,4 +84,3 @@ namespace WebApp.Controllers.Api
return NoContent();
}
}
}

View File

@@ -1,4 +1,3 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using WebApp.Data;
using WebApp.Entities;
@@ -15,12 +14,20 @@ builder.Services.AddDefaultIdentity<User>(options => options.SignIn.RequireConfi
.AddEntityFrameworkStores<ApplicationDbContext>();
builder.Services.AddControllersWithViews();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "hermes", Version = "v1" });
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseMigrationsEndPoint();
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "hermes v1"));
}
else
{

View File

@@ -21,8 +21,13 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.OpenApi" Version="1.6.24" />
<PackageReference Include="Npgsql" Version="9.0.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="8.1.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="8.1.1" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="8.1.1" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="8.1.1" />
</ItemGroup>
<ItemGroup>