A while ago I created a new Blazor Web App and put in the Visual Studio solution some projects. One of the projects is a Blazor server-side app with rendermode InterractiveServer. A second project is a Blazor WebAssembly app, where the team I'm on intends to put most of the data collection pages.
A third project is a Minimal API project which I had intended to be utilized by both the server-side and client-side projects, by referencing the Minimal API project using a project reference from both the server-side and client-side projects. That, I now realize, was a serious mistake.
So, I decided to create a new Visual Studio solution and migrate the Minimal API project out of the first VS solution, into the new VS solution. Another thing I'm trying to do with this new solution is utilize Swagger. However, now that I've got the new VS solution created and fixed all of the dependencies in it, I've found that when debugging this new project, it never brings up Swagger. I tried using the free version of GitHub Copilot to resolve this issue. However, after modifying 4 files with multiple interactions with GitHub Copilot, I was no nearer to resolving the issue than I was before. In my experience, once GitHub Copilot starts down a rabbit trail, it will go on modifying more a more files, resolving issues it created rather than the issue I need solved. Therefore, I am going to post here the contents of the Program.cs file in the Minimal API project, minus several endpoints which I don't believe will add much to this discussion. I'm hoping someone here can point me to the mistake I've made. Or, if I should supply another file for reference, please let me know. Here's the contents of the Program.cs file:
using Azure.Identity;
using Azure.Extensions.AspNetCore.Configuration.Secrets;
using FPTimetrackCore.DataActionsAPI;
using FPTimetrackCore.DataActionsAPI.DTO;
using FPTimetrackCore.DataActionsAPI.Model;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using System.Net;
using System;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.OpenApi.Models;
var builder = WebApplication.CreateBuilder(args);
// -- Key Vault Configuration --
var isDev = builder.Environment.IsDevelopment();
var vaultUri = Environment.GetEnvironmentVariable("VaultUri");
if(!isDev && !string.IsNullOrWhiteSpace(vaultUri))
{
builder.Configuration.AddAzureKeyVault(new Uri(vaultUri), new DefaultAzureCredential());
}
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Title = "FPTimetrackCore.DataActionsAPI",
Version = "v1"
});
});
builder.Services.AddAutoMapper(typeof(MappingConfig));
builder.Configuration.AddAzureKeyVault(
new Uri($"https://MYKEYVAULT.vault.azure.net/"),
new DefaultAzureCredential());
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "FPTimetrackCore.DataActionsAPI v1");
});
}
app.UseHttpsRedirection();
static SaveData GetConnectionObject(bool prodConn)
{
IConfiguration configuration = null;
if (prodConn) // Is this really the best way to do this?
{
configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables()
.Build();
}
else
{
configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.Development.json")
.AddEnvironmentVariables()
.Build();
}
var lib = new SaveData(configuration);
return lib;
}
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "FPTimetrackCore.nEWAPI v1");
});
}
const int MAX_MONTHS = -3; // This is the number of months to go back from today, from the original Family Planning Timetrack application.
// And I didn't put it as an API route parameter.
app.MapGet("/api/getphdusers/{prodConn}/{Active}", (IConfiguration _config, IMapper _mapper, bool prodConn = true, bool Active = true) =>
{
TimetrackContext ctx = GetDbContext(_config, prodConn);
IQueryable<PhdUser> phdUsers = null;
if (Active)
{
phdUsers = ctx.PhdUsers.Where(a => a.PhdUserStatus == "Active");
}
else
{
phdUsers = ctx.PhdUsers;
}
IOrderedQueryable<PhdUser> users = phdUsers.OrderBy(o => o.PhdUserName);
var phdUserArray = users.ToArray();
var PhdUsersDTOArray = _mapper.Map<PhdUserDTO[]>(phdUserArray);
APIResponse response = new()
{
IsSuccess = true,
Result = PhdUsersDTOArray,
StatusCode = System.Net.HttpStatusCode.OK
};
return Results.Ok(response);
})
.WithName("GetPhdUsers")
.WithOpenApi()
.Produces<APIResponse>(StatusCodes.Status200OK);
// Other endpoints go here, but omitted for brevity.
app.Run();
ccc