Skip to content

Commit

Permalink
Update Swagger configuration in web API
Browse files Browse the repository at this point in the history
This commit refines the use of Swagger for API documentation in the web application. It introduces the OpenApi.Models namespace and modifies the Swagger generation setup. Also, some additional adjustments have been made to clean up and reorganize the code for better readability.
  • Loading branch information
Al4ric committed Nov 22, 2023
1 parent bd0c6c0 commit fe5ef7e
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions SimpleWebApi8/Program.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,30 @@
using Microsoft.OpenApi.Models;
using Marten;
using Marten.Events.Projections;
using SimpleWebApi8;
using Weasel.Core;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Event Sourcing API", Version = "v1" }); });
var connectionString = builder.Configuration.GetConnectionString("Postgres");

builder.Services.AddMarten(options =>
{
if (connectionString != null) options.Connection(connectionString);
options.AutoCreateSchemaObjects = AutoCreate.All;
})
.ApplyAllDatabaseChangesOnStartup();

builder.Services.AddScoped(GetDeviceStore);

var app = builder.Build();

app.UseSwagger();
app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); });

app.MapGet("/", () => "Hello World!");
// add endpoint that returns a random number
app.MapGet("/random", () => new Random().Next(1, 100).ToString());

app.MapGet("createDevice", DeviceHandlers.CreateDevice);

app.MapGet("device/{deviceId:guid}", DeviceHandlers.GetDeviceById);

app.Run();
return;

Expand All @@ -44,4 +38,6 @@ DocumentStore GetDeviceStore(IServiceProvider serviceProvider)
return documentStore;
}

public partial class Program { }
public partial class Program
{
}

0 comments on commit fe5ef7e

Please sign in to comment.