Skip to content

Commit

Permalink
Add swagger to preservation api
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldgray committed Apr 30, 2024
1 parent 767e401 commit c9647f3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
6 changes: 6 additions & 0 deletions LeedsExperiment/Preservation.API/Preservation.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\PreservationApiClient\PreservationApiClient.csproj" />
<ProjectReference Include="..\Preservation\Preservation.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

</Project>
19 changes: 18 additions & 1 deletion LeedsExperiment/Preservation.API/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.OpenApi.Models;
using Preservation;
using PreservationApiClient;

Expand All @@ -21,7 +23,20 @@
client.DefaultRequestHeaders.Add("Accept", "application/json");
});

// TODO - swagger
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(opts =>
{
opts.SwaggerDoc("v1", new OpenApiInfo
{
Title = "UoL Demo Preservation API",
Version = "v0.1",
Description =
"Preservation API is consumed by the applications we are going to build. For demo/test purposes only, focussed on 'happy path' (minimal error handling etc)."
});

var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
opts.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));
});

var app = builder.Build();

Expand All @@ -40,6 +55,8 @@
app.MapGet("/deposits/{id}/importJobs/diff", (string id) => $"Get importJob JSON for files in Deposit {id}");
app.MapPost("/deposits/{id}/importJobs", (string id) => "Import data into Fedora");

app.UseSwagger();
app.UseSwaggerUI();
app.UseHttpsRedirection();
app.MapControllers();
app.UseHttpLogging();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5074",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
Expand All @@ -14,6 +15,7 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7169;http://localhost:5074",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
Expand Down

0 comments on commit c9647f3

Please sign in to comment.