feat: freeze v1 transport contracts (#4)
quality-gate / quality (push) Successful in 51s

Closes #4
This commit is contained in:
KyuubiYoru
2026-07-16 04:52:38 +02:00
parent e626b89909
commit 69c8b2d2bc
43 changed files with 3737 additions and 12 deletions
+49 -3
View File
@@ -1,8 +1,39 @@
using System.Net;
using FinalFactory.Rendezvous.Contracts;
using FinalFactory.Rendezvous.Server.Http;
using FinalFactory.Rendezvous.Server.Transport;
using Microsoft.OpenApi;
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
bool isOpenApiGeneration = Environment.GetCommandLineArgs().Any(static argument =>
string.Equals(
Path.GetFileName(argument),
"dotnet-getdocument.dll",
StringComparison.OrdinalIgnoreCase));
builder.Services.AddOpenApi("v1", static options =>
options.AddSchemaTransformer(static (schema, context, cancellationToken) =>
{
Type type = context.JsonTypeInfo.Type;
if (type == typeof(GameId)
|| type == typeof(EnvironmentId)
|| type == typeof(RegionId))
{
schema.Type = JsonSchemaType.String;
}
else if (type == typeof(SessionListingId)
|| type == typeof(LeaseId)
|| type == typeof(JoinAttemptId)
|| type == typeof(MediationHandle))
{
schema.Type = JsonSchemaType.String;
schema.Format = "uuid";
}
return Task.CompletedTask;
}));
builder.Services.ConfigureHttpJsonOptions(static options =>
ContractJson.Configure(options.SerializerOptions));
builder.Services
.AddOptions<UdpMediatorOptions>()
.BindConfiguration(UdpMediatorOptions.SectionName)
@@ -12,16 +43,31 @@ builder.Services
$"{UdpMediatorOptions.SectionName}:ListenAddress must be an IP address.")
.ValidateOnStart();
builder.Services.AddSingleton<UdpMediatorService>();
builder.Services.AddHostedService(static services => services.GetRequiredService<UdpMediatorService>());
if (!isOpenApiGeneration)
{
builder.Services.AddHostedService(static services =>
services.GetRequiredService<UdpMediatorService>());
}
WebApplication app = builder.Build();
app.MapGet("/health/live", static () => Results.Ok(new { status = "live" }));
app.MapOpenApi();
app.MapRendezvousContractEndpoints();
app.MapGet(
"/health/live",
static () => Results.Ok(new HealthResponse { Status = "live" }))
.Produces<HealthResponse>()
.WithName("GetLiveness")
.WithTags("Health");
app.MapGet(
"/health/ready",
static (UdpMediatorService mediator) => mediator.LocalEndpoint is null
? Results.StatusCode(StatusCodes.Status503ServiceUnavailable)
: Results.Ok(new { status = "ready" }));
: Results.Ok(new HealthResponse { Status = "ready" }))
.Produces<HealthResponse>()
.Produces(StatusCodes.Status503ServiceUnavailable)
.WithName("GetReadiness")
.WithTags("Health");
await app.RunAsync();