Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions QrCodeApiApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Hosting;

namespace QrCodeApiApp
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
CreateHostBuilder(args).Build().Run();
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
7 changes: 4 additions & 3 deletions QrCodeApiApp/QrCodeApiApp.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand All @@ -10,8 +12,7 @@

<ItemGroup>
<PackageReference Include="joelbyford.BasicAuth" Version="1.2.0" />
<PackageReference Include="Microsoft.OpenApi" Version="1.6.24" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.1" />
<PackageReference Include="System.Drawing.Common" Version="9.0.4" />
<PackageReference Include="ZXing.Net" Version="0.16.10" />
</ItemGroup>
Expand Down
15 changes: 12 additions & 3 deletions QrCodeApiApp/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;
using joelbyford;
using System.IO;
using System.Text.Json;
using System.Reflection;

namespace QrCodeApiApp
{
Expand All @@ -35,6 +36,11 @@ public void ConfigureServices(IServiceCollection services)
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "QrCodeApiApp", Version = "v1" });
// Set the comments path for the Swagger JSON and UI.
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);

});
}

Expand All @@ -44,9 +50,12 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "QrCodeApiApp v1"));
}

// Always share the swagger info
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "QrCodeApiApp v1"));

//Insert the Basic Authentication Middleware handler *ONLY IF* it was enabled in appsettings.json
bool basicAuthEnabled = this.Configuration.GetValue<bool>("AppSettings:BasicAuth:Enabled");

Expand Down
11 changes: 11 additions & 0 deletions QrCodeApiApp/test/manualTesting.http
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Provided here are several examples that can be used to test the API that it is functioning correctly when running on the localhost.
#
# To make use of this file, you can use the REST Client extension for Visual Studio Code:
# https://marketplace.visualstudio.com/items?itemName=humao.rest-client

###########################
# Swagger/Swashbuckle Test
# =========================
GET http://localhost:5000/swagger

####
# Example GET sending the text "SomeTextToEncode" - ANONYMOUS ACCESS
GET http://localhost:5000/api/encode?text=SomeTextToEncode&size=150

Expand Down
Loading