Skip to content

Commit 59cf450

Browse files
committed
feat: register swagger endpoints for data and run services
1 parent fa6fbde commit 59cf450

7 files changed

Lines changed: 63 additions & 0 deletions

File tree

src/Abacus.Data.Service/Abacus.Data.Service.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="$(MicrosoftExtensionsVersion)" />
1515
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(MicrosoftExtensionsVersion)" />
1616
<PackageReference Include="Microsoft.Extensions.Options" Version="$(MicrosoftExtensionsVersion)" />
17+
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.2.3" />
1718
</ItemGroup>
1819
</Project>

src/Abacus.Data.Service/Program.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,28 @@ public static void Main(string[] args)
4242
builder.Services.AddSingleton<IAssessmentReportRenderer, AssessmentReportRenderer>();
4343
builder.Services.AddHostedService<QaDataDatabaseInitializer>();
4444

45+
builder.Services.AddEndpointsApiExplorer();
46+
builder.Services.AddSwaggerGen(c =>
47+
{
48+
c.SwaggerDoc("v1", new Microsoft.OpenApi.OpenApiInfo
49+
{
50+
Title = "Abacus Data Service API",
51+
Version = "v1"
52+
});
53+
});
54+
4555
WebApplication app = builder.Build();
4656

4757
app.UseExceptionHandler();
4858
app.UseStatusCodePages();
4959

60+
app.UseSwagger();
61+
app.UseSwaggerUI(c =>
62+
{
63+
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Abacus Data Service API v1");
64+
c.RoutePrefix = "swagger";
65+
});
66+
5067
app.MapCatalogEndpoints();
5168
app.MapAssessmentEndpoints();
5269
app.MapGet("/health/live", () => Results.Ok(new { status = "live" }));

src/Abacus.Run.Service/Abacus.Run.Service.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
<ItemGroup>
88
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="10.8.3" />
9+
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.2.3" />
910
<ProjectReference Include="../Abacus.Run/Abacus.Run.csproj" />
1011
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.9" />
1112
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.9" />

src/Abacus.Run.Service/Program.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,28 @@
7171
ChatClientEmbeddingGenerator>();
7272
}
7373

74+
builder.Services.AddEndpointsApiExplorer();
75+
builder.Services.AddSwaggerGen(c =>
76+
{
77+
c.SwaggerDoc("v1", new Microsoft.OpenApi.OpenApiInfo
78+
{
79+
Title = "Abacus Run Service API",
80+
Version = "v1"
81+
});
82+
});
83+
7484
WebApplication app = builder.Build();
7585

7686
app.UseExceptionHandler();
7787
app.UseStatusCodePages();
7888

89+
app.UseSwagger();
90+
app.UseSwaggerUI(c =>
91+
{
92+
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Abacus Run Service API v1");
93+
c.RoutePrefix = "swagger";
94+
});
95+
7996
app.UseStaticFiles();
8097
app.UseRouting();
8198

tests/Abacus.Run.IntegrationTests/Abacus.Run.IntegrationTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
</PropertyGroup>
55
<ItemGroup>
66
<ProjectReference Include="../../src/Abacus.Run.Service/Abacus.Run.Service.csproj" />
7+
<ProjectReference Include="../../src/Abacus.Data.Service/Abacus.Data.Service.csproj" />
78
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
89
<PackageReference Include="xunit" Version="2.9.2" />
910
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />

tests/Abacus.Run.IntegrationTests/ControlPlaneIntegrationTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,16 @@ public async Task Layout_asset_links_resolve()
123123
asset.StatusCode.Should().Be(HttpStatusCode.OK, $"{match.Groups[1].Value} is referenced by the layout");
124124
}
125125
}
126+
127+
[Fact]
128+
public async Task Swagger_Endpoints_Return_200_OK()
129+
{
130+
HttpResponseMessage swaggerJson = await _client.GetAsync("/swagger/v1/swagger.json");
131+
swaggerJson.StatusCode.Should().Be(HttpStatusCode.OK);
132+
string json = await swaggerJson.Content.ReadAsStringAsync();
133+
json.Should().Contain("Abacus Run Service API");
134+
135+
HttpResponseMessage swaggerUi = await _client.GetAsync("/swagger/");
136+
swaggerUi.StatusCode.Should().Be(HttpStatusCode.OK);
137+
}
126138
}

tests/Abacus.Run.IntegrationTests/Workflows/SuitabilityQa/QaDataServiceApiTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,18 @@ public async Task Report_is_unavailable_until_the_assessment_completes()
180180
report.StatusCode.Should().Be(HttpStatusCode.Conflict,
181181
"an unfinished assessment has no report to serve, and an empty body would read as 'no findings'");
182182
}
183+
184+
[Fact]
185+
public async Task Swagger_Endpoints_Return_200_OK()
186+
{
187+
using HttpClient client = _service.CreateClient();
188+
189+
HttpResponseMessage swaggerJson = await client.GetAsync("/swagger/v1/swagger.json");
190+
swaggerJson.StatusCode.Should().Be(HttpStatusCode.OK);
191+
string json = await swaggerJson.Content.ReadAsStringAsync();
192+
json.Should().Contain("Abacus Data Service API");
193+
194+
HttpResponseMessage swaggerUi = await client.GetAsync("/swagger/");
195+
swaggerUi.StatusCode.Should().Be(HttpStatusCode.OK);
196+
}
183197
}

0 commit comments

Comments
 (0)