diff --git a/src/SkillServer/Endpoints.cs b/src/SkillServer/Endpoints.cs index 1b2f477..93ff4f3 100644 --- a/src/SkillServer/Endpoints.cs +++ b/src/SkillServer/Endpoints.cs @@ -50,7 +50,9 @@ private static void MapSkillEndpoints(this WebApplication app) private static void MapHealthEndpoints(this WebApplication app) { - app.MapGet("/health", () => Results.Ok(new { status = "healthy", timestamp = DateTimeOffset.UtcNow })); + app.MapGet("/health", () => Results.Json( + new HealthResponse { Status = "healthy", Timestamp = DateTimeOffset.UtcNow }, + SkillServerJsonContext.Default.HealthResponse)); } private static async Task ListSkills( diff --git a/src/SkillServer/Models/ApiModels.cs b/src/SkillServer/Models/ApiModels.cs index 49c2003..aa36635 100644 --- a/src/SkillServer/Models/ApiModels.cs +++ b/src/SkillServer/Models/ApiModels.cs @@ -186,3 +186,15 @@ public sealed record ApiKeySummary [JsonPropertyName("expiresAt")] public DateTimeOffset? ExpiresAt { get; init; } } + +/// +/// Response from the health check endpoint. +/// +public sealed record HealthResponse +{ + [JsonPropertyName("status")] + public required string Status { get; init; } + + [JsonPropertyName("timestamp")] + public required DateTimeOffset Timestamp { get; init; } +} diff --git a/src/SkillServer/Models/SkillServerJsonContext.cs b/src/SkillServer/Models/SkillServerJsonContext.cs index 5355796..262c336 100644 --- a/src/SkillServer/Models/SkillServerJsonContext.cs +++ b/src/SkillServer/Models/SkillServerJsonContext.cs @@ -26,6 +26,7 @@ namespace SkillServer.Models; [JsonSerializable(typeof(IReadOnlyList))] [JsonSerializable(typeof(IReadOnlyList))] [JsonSerializable(typeof(IReadOnlyList))] +[JsonSerializable(typeof(HealthResponse))] [JsonSourceGenerationOptions( PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] diff --git a/tests/SkillServer.Integration.Tests/SkillServerIntegrationTests.cs b/tests/SkillServer.Integration.Tests/SkillServerIntegrationTests.cs index 7d0a497..71a8d28 100644 --- a/tests/SkillServer.Integration.Tests/SkillServerIntegrationTests.cs +++ b/tests/SkillServer.Integration.Tests/SkillServerIntegrationTests.cs @@ -30,6 +30,11 @@ public async Task Health_ReturnsOk() var response = await _fixture.HttpClient.GetAsync("/health", ct); Assert.Equal(HttpStatusCode.OK, response.StatusCode); + + var body = await response.Content.ReadFromJsonAsync(ct); + Assert.NotNull(body); + Assert.Equal("healthy", body.Status); + Assert.True(body.Timestamp > DateTimeOffset.MinValue); } [Fact]