mirror of
https://git.tonybark.com/tonytins/bark.api.git
synced 2026-02-10 16:24:47 -05:00
Add Swagger/OpenAPI support for BarkAPI
Integrated OpenAPI and Swagger UI for BarkAPI, including endpoint documentation and UI configuration for development environment. This will enhance API discoverability and testing during development.
This commit is contained in:
parent
3c43ce2f71
commit
dc4af28f97
1 changed files with 19 additions and 0 deletions
19
Program.cs
19
Program.cs
|
|
@ -1,8 +1,27 @@
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
builder.Services.AddDbContext<TodoDb>(opt => opt.UseInMemoryDatabase("TodoDb"));
|
builder.Services.AddDbContext<TodoDb>(opt => opt.UseInMemoryDatabase("TodoDb"));
|
||||||
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
|
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
|
||||||
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
|
builder.Services.AddOpenApiDocument(cfg =>
|
||||||
|
{
|
||||||
|
cfg.DocumentName = "BarkAPI";
|
||||||
|
cfg.Title = "BarkAPI v1";
|
||||||
|
cfg.Version = "v1";
|
||||||
|
});
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
if (app.Environment.IsDevelopment())
|
||||||
|
{
|
||||||
|
app.UseOpenApi();
|
||||||
|
app.UseSwaggerUi(cfg =>
|
||||||
|
{
|
||||||
|
cfg.DocumentTitle = "BarkAPI";
|
||||||
|
cfg.Path = "/api";
|
||||||
|
cfg.DocumentPath = "/api/{documentName}/swagger.json}";
|
||||||
|
cfg.DocExpansion = "list";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
app.MapGet("/", () => "Bark API");
|
app.MapGet("/", () => "Bark API");
|
||||||
|
|
||||||
app.MapGet("/todo", async (TodoDb db)
|
app.MapGet("/todo", async (TodoDb db)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue