Skip to content

Commit 8ee72c0

Browse files
Merge pull request #51 from TransactionProcessing/documentation/#47_swaggerpages
remove versioning
2 parents c4d4aeb + cd87048 commit 8ee72c0

File tree

5 files changed

+74
-184
lines changed

5 files changed

+74
-184
lines changed

MessagingService.Client/MessagingServiceClient.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ public MessagingServiceClient(Func<String, String> baseAddressResolver,
4242
HttpClient httpClient) : base(httpClient)
4343
{
4444
this.BaseAddressResolver = baseAddressResolver;
45-
46-
// Add the API version header
47-
this.HttpClient.DefaultRequestHeaders.Add("api-version", "1.0");
4845
}
4946

5047
#endregion

MessagingService/Common/ConfigureSwaggerOptions.cs

Lines changed: 0 additions & 127 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
namespace MessagingService.Common
2+
{
3+
using System.Diagnostics.CodeAnalysis;
4+
using System.Linq;
5+
using Microsoft.AspNetCore.Mvc.ApiExplorer;
6+
using Microsoft.OpenApi.Models;
7+
using Swashbuckle.AspNetCore.SwaggerGen;
8+
9+
/// <summary>
10+
/// Represents the Swagger/Swashbuckle operation filter used to document the implicit API version parameter.
11+
/// </summary>
12+
/// <remarks>This <see cref="IOperationFilter"/> is only required due to bugs in the <see cref="SwaggerGenerator"/>.
13+
/// Once they are fixed and published, this class can be removed.</remarks>
14+
[ExcludeFromCodeCoverage]
15+
public class SwaggerDefaultValues : IOperationFilter
16+
{
17+
#region Methods
18+
19+
/// <summary>
20+
/// Applies the filter to the specified operation using the given context.
21+
/// </summary>
22+
/// <param name="operation">The operation to apply the filter to.</param>
23+
/// <param name="context">The current operation filter context.</param>
24+
public void Apply(OpenApiOperation operation,
25+
OperationFilterContext context)
26+
{
27+
ApiDescription apiDescription = context.ApiDescription;
28+
29+
if (operation.Parameters == null)
30+
{
31+
return;
32+
}
33+
34+
foreach (OpenApiParameter parameter in operation.Parameters)
35+
{
36+
ApiParameterDescription description = apiDescription.ParameterDescriptions.First(p => p.Name == parameter.Name);
37+
38+
if (parameter.Description == null)
39+
{
40+
parameter.Description = description.ModelMetadata?.Description;
41+
}
42+
43+
parameter.Required |= description.IsRequired;
44+
}
45+
}
46+
47+
#endregion
48+
}
49+
}

MessagingService/MessagingService.csproj

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,19 @@
88
<ItemGroup>
99
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="5.0.1" />
1010
<PackageReference Include="AspNetCore.HealthChecks.Uris" Version="5.0.1" />
11-
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.2" />
12-
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.2" />
11+
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.4" />
12+
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.4" />
1313
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.8" />
1414
<PackageReference Include="Shared" Version="1.0.5" />
15-
<PackageReference Include="NuGet.Versioning" Version="5.9.0" />
16-
17-
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="4.2.0" />
18-
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="4.2.0" />
1915
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
2016
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="5.0.0" />
21-
<PackageReference Include="NLog.Extensions.Logging" Version="1.7.0" />
22-
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
23-
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.6.3" />
24-
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="6.0.1" />
25-
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="5.6.3" />
26-
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="5.6.3" />
27-
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="5.6.3" />
17+
<PackageReference Include="NLog.Extensions.Logging" Version="1.7.2" />
18+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.1" />
19+
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.1.1" />
20+
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="6.1.0" />
21+
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.1.1" />
22+
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.1.1" />
23+
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.1.1" />
2824
</ItemGroup>
2925

3026
<ItemGroup>

MessagingService/Startup.cs

Lines changed: 16 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace MessagingService
1616
using System.IO;
1717
using System.Net.Http;
1818
using System.Reflection;
19+
using System.Runtime.Intrinsics;
1920
using BusinessLogic.Common;
2021
using BusinessLogic.EventHandling;
2122
using BusinessLogic.RequestHandlers;
@@ -33,14 +34,12 @@ namespace MessagingService
3334
using MediatR;
3435
using Microsoft.AspNetCore.Authentication.JwtBearer;
3536
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
36-
using Microsoft.AspNetCore.Mvc.ApiExplorer;
37-
using Microsoft.AspNetCore.Mvc.Versioning;
3837
using Microsoft.Extensions.Diagnostics.HealthChecks;
3938
using Microsoft.Extensions.Options;
39+
using Microsoft.OpenApi.Models;
4040
using Newtonsoft.Json;
4141
using Newtonsoft.Json.Serialization;
4242
using NLog.Extensions.Logging;
43-
using NuGet.Versioning;
4443
using Service.Services.Email.IntegrationTest;
4544
using Service.Services.SMSServices.IntegrationTest;
4645
using Shared.DomainDrivenDesign.EventSourcing;
@@ -233,35 +232,20 @@ private void ConfigureMiddlewareServices(IServiceCollection services)
233232
name: "Eventstore",
234233
failureStatus: HealthStatus.Unhealthy,
235234
tags: new string[] { "db", "eventstore" });
236-
237-
var version = ConfigurationReader.GetValue("AppSettings", "ApiVersion");
238-
var v = NuGetVersion.Parse(version);
239-
services.AddApiVersioning(
240-
options =>
241-
{
242-
// reporting api versions will return the headers "api-supported-versions" and "api-deprecated-versions"
243-
options.ReportApiVersions = true;
244-
options.DefaultApiVersion = new ApiVersion(v.Major, v.Minor, $"Patch{v.Patch}");
245-
options.AssumeDefaultVersionWhenUnspecified = true;
246-
options.ApiVersionReader = new HeaderApiVersionReader("api-version");
247-
});
248-
249-
services.AddVersionedApiExplorer(
250-
options =>
251-
{
252-
// add the versioned api explorer, which also adds IApiVersionDescriptionProvider service
253-
// note: the specified format code will format the version as "'v'major[.minor][-status]"
254-
options.GroupNameFormat = "'v'VVV";
255-
256-
// note: this option is only necessary when versioning by url segment. the SubstitutionFormat
257-
// can also be used to control the format of the API version in route templates
258-
options.SubstituteApiVersionInUrl = true;
259-
});
260-
261-
services.AddTransient<IConfigureOptions<SwaggerGenOptions>, ConfigureSwaggerOptions>();
262-
235+
263236
services.AddSwaggerGen(c =>
264237
{
238+
c.SwaggerDoc("v1", new OpenApiInfo
239+
{
240+
Title = "Messaging API",
241+
Version = "1.0",
242+
Description = "A REST Api to manage sending of various messages over different formats, currently only Email and SMS are supported.",
243+
Contact = new OpenApiContact
244+
{
245+
Name = "Stuart Ferguson",
246+
247+
}
248+
});
265249
// add a custom operation filter which sets default values
266250
c.OperationFilter<SwaggerDefaultValues>();
267251
c.ExampleFilters();
@@ -305,8 +289,7 @@ private void ConfigureMiddlewareServices(IServiceCollection services)
305289
}
306290

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

@@ -350,15 +333,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerF
350333
});
351334
app.UseSwagger();
352335

353-
app.UseSwaggerUI(
354-
options =>
355-
{
356-
// build a swagger endpoint for each discovered API version
357-
foreach (ApiVersionDescription description in provider.ApiVersionDescriptions)
358-
{
359-
options.SwaggerEndpoint($"/swagger/{description.GroupName}/swagger.json", description.GroupName.ToUpperInvariant());
360-
}
361-
});
336+
app.UseSwaggerUI();
362337
}
363338
}
364339
}

0 commit comments

Comments
 (0)