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
3 changes: 0 additions & 3 deletions MessagingService.Client/MessagingServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ public MessagingServiceClient(Func<String, String> baseAddressResolver,
HttpClient httpClient) : base(httpClient)
{
this.BaseAddressResolver = baseAddressResolver;

// Add the API version header
this.HttpClient.DefaultRequestHeaders.Add("api-version", "1.0");
}

#endregion
Expand Down
127 changes: 0 additions & 127 deletions MessagingService/Common/ConfigureSwaggerOptions.cs

This file was deleted.

49 changes: 49 additions & 0 deletions MessagingService/Common/SwaggerDefaultValues.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
namespace MessagingService.Common
{
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;

/// <summary>
/// Represents the Swagger/Swashbuckle operation filter used to document the implicit API version parameter.
/// </summary>
/// <remarks>This <see cref="IOperationFilter"/> is only required due to bugs in the <see cref="SwaggerGenerator"/>.
/// Once they are fixed and published, this class can be removed.</remarks>
[ExcludeFromCodeCoverage]
public class SwaggerDefaultValues : IOperationFilter
{
#region Methods

/// <summary>
/// Applies the filter to the specified operation using the given context.
/// </summary>
/// <param name="operation">The operation to apply the filter to.</param>
/// <param name="context">The current operation filter context.</param>
public void Apply(OpenApiOperation operation,
OperationFilterContext context)
{
ApiDescription apiDescription = context.ApiDescription;

if (operation.Parameters == null)
{
return;
}

foreach (OpenApiParameter parameter in operation.Parameters)
{
ApiParameterDescription description = apiDescription.ParameterDescriptions.First(p => p.Name == parameter.Name);

if (parameter.Description == null)
{
parameter.Description = description.ModelMetadata?.Description;
}

parameter.Required |= description.IsRequired;
}
}

#endregion
}
}
22 changes: 9 additions & 13 deletions MessagingService/MessagingService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,19 @@
<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="5.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.Uris" Version="5.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.4" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.8" />
<PackageReference Include="Shared" Version="1.0.5" />
<PackageReference Include="NuGet.Versioning" Version="5.9.0" />

<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="4.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="4.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="5.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.7.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.6.3" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="6.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="5.6.3" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="5.6.3" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="5.6.3" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.7.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.1.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="6.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.1.1" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.1.1" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.1.1" />
</ItemGroup>

<ItemGroup>
Expand Down
57 changes: 16 additions & 41 deletions MessagingService/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace MessagingService
using System.IO;
using System.Net.Http;
using System.Reflection;
using System.Runtime.Intrinsics;
using BusinessLogic.Common;
using BusinessLogic.EventHandling;
using BusinessLogic.RequestHandlers;
Expand All @@ -33,14 +34,12 @@ namespace MessagingService
using MediatR;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.Versioning;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using NLog.Extensions.Logging;
using NuGet.Versioning;
using Service.Services.Email.IntegrationTest;
using Service.Services.SMSServices.IntegrationTest;
using Shared.DomainDrivenDesign.EventSourcing;
Expand Down Expand Up @@ -233,35 +232,20 @@ private void ConfigureMiddlewareServices(IServiceCollection services)
name: "Eventstore",
failureStatus: HealthStatus.Unhealthy,
tags: new string[] { "db", "eventstore" });

var version = ConfigurationReader.GetValue("AppSettings", "ApiVersion");
var v = NuGetVersion.Parse(version);
services.AddApiVersioning(
options =>
{
// reporting api versions will return the headers "api-supported-versions" and "api-deprecated-versions"
options.ReportApiVersions = true;
options.DefaultApiVersion = new ApiVersion(v.Major, v.Minor, $"Patch{v.Patch}");
options.AssumeDefaultVersionWhenUnspecified = true;
options.ApiVersionReader = new HeaderApiVersionReader("api-version");
});

services.AddVersionedApiExplorer(
options =>
{
// add the versioned api explorer, which also adds IApiVersionDescriptionProvider service
// note: the specified format code will format the version as "'v'major[.minor][-status]"
options.GroupNameFormat = "'v'VVV";

// note: this option is only necessary when versioning by url segment. the SubstitutionFormat
// can also be used to control the format of the API version in route templates
options.SubstituteApiVersionInUrl = true;
});

services.AddTransient<IConfigureOptions<SwaggerGenOptions>, ConfigureSwaggerOptions>();


services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Title = "Messaging API",
Version = "1.0",
Description = "A REST Api to manage sending of various messages over different formats, currently only Email and SMS are supported.",
Contact = new OpenApiContact
{
Name = "Stuart Ferguson",
Email = "golfhandicapping@btinternet.com"
}
});
// add a custom operation filter which sets default values
c.OperationFilter<SwaggerDefaultValues>();
c.ExampleFilters();
Expand Down Expand Up @@ -305,8 +289,7 @@ private void ConfigureMiddlewareServices(IServiceCollection services)
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory,
IApiVersionDescriptionProvider provider)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
{
String nlogConfigFilename = "nlog.config";

Expand Down Expand Up @@ -350,15 +333,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerF
});
app.UseSwagger();

app.UseSwaggerUI(
options =>
{
// build a swagger endpoint for each discovered API version
foreach (ApiVersionDescription description in provider.ApiVersionDescriptions)
{
options.SwaggerEndpoint($"/swagger/{description.GroupName}/swagger.json", description.GroupName.ToUpperInvariant());
}
});
app.UseSwaggerUI();
}
}
}