Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Swagger doesn't come up when I start debugging

$
0
0

I've used Swagger for several ASP.NET Core applications, and it works fine. So, I don't understand why it isn't coming up now in a new Blazor app I'm working on. The Blazor Web Application I've been working on (I am using Visual Studio 2022 and .NET 9). The application has 4 VS projects in the solutions, one of them was a Minimal API app. Due to problems, I encountered with that configuration, I have decided to migrate the Minimal API project out of that VS solution, into a new VS solution that has only one VS project, which is the Minimal API from the other VS solution.

However, I've found that when debugging the new VS solution it does not bring up Swagger. I've tried using GitHub Copilot, but that just resulted in following Copilot running along a rabbit trail. So, I'm posting the Program.cs file from the new VS solution. Here is the code from the Program.cs file:

using AutoMapper;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://this.is.not.real/"),    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.API v1");    });}const int MAX_MONTHS = -3; // This is the number of months to go back from today, from the original Family Planning Timetrack application.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();

Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>