Skip to content

Commit d7d656e

Browse files
PR Feedback
1 parent 9c3599c commit d7d656e

File tree

8 files changed

+76
-91
lines changed

8 files changed

+76
-91
lines changed

SampleApp9000/Controllers/WeatherForecastController.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ namespace SampleApp9000.Controllers;
99
[Route("[controller]")]
1010
public class WeatherForecastController : ControllerBase
1111
{
12-
private static readonly string[] Summaries =
13-
{
12+
private static readonly string[] Summaries =
13+
[
1414
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
15-
};
15+
];
1616

1717
[HttpGet]
1818
public IEnumerable<WeatherForecast> Get()
1919
{
2020
var rng = new Random();
21+
2122
return
2223
Enumerable
2324
.Range(1, 5)

SampleApp9000/Startup.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Microsoft.AspNetCore.Builder;
22
using Microsoft.AspNetCore.Hosting;
33
using Microsoft.OpenApi;
4-
using Microsoft.Extensions.Configuration;
54
using Microsoft.Extensions.DependencyInjection;
65
using Microsoft.Extensions.Hosting;
76
using Swashbuckle.Servers.Extension;
@@ -10,13 +9,6 @@ namespace SampleApp9000;
109

1110
public class Startup
1211
{
13-
public Startup(IConfiguration configuration)
14-
{
15-
Configuration = configuration;
16-
}
17-
18-
public IConfiguration Configuration { get; }
19-
2012
// This method gets called by the runtime. Use this method to add services to the container.
2113
public void ConfigureServices(IServiceCollection services)
2214
{
@@ -37,11 +29,10 @@ public void ConfigureServices(IServiceCollection services)
3729

3830
c.WithServers
3931
(
40-
new[]
41-
{
32+
[
4233
new OpenApiServer { Url = "http://localhost:5000" },
4334
new OpenApiServer { Url = "https://www.yourcustomdomain.com" }
44-
}
35+
]
4536
);
4637
});
4738
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:Boolean x:Key="/Default/UserDictionary/Words/=sampleapp/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

Swashbuckle.Servers.Extension/Extensions/OpenApiServerExtensions.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22
using System.Collections.Generic;
33
using Microsoft.OpenApi;
44

5-
namespace Swashbuckle.Servers.Extension.Extensions
5+
namespace Swashbuckle.Servers.Extension.Extensions;
6+
7+
public static class OpenApiServerExtensions
68
{
7-
public static class OpenApiServerExtensions
9+
public static OpenApiServer WithVariable(this OpenApiServer server, string key, OpenApiServerVariable value)
810
{
9-
public static OpenApiServer WithVariable(this OpenApiServer server, string key, OpenApiServerVariable value)
10-
{
11-
if (server == null)
12-
throw new ArgumentNullException(nameof(server));
11+
ArgumentNullException.ThrowIfNull(server);
12+
13+
server.Variables ??= new Dictionary<string, OpenApiServerVariable>();
14+
server.Variables.Add(key, value);
1315

14-
server.Variables ??= new Dictionary<string, OpenApiServerVariable>();
15-
server.Variables.Add(key, value);
16-
return server;
17-
}
16+
return server;
1817
}
1918
}

Swashbuckle.Servers.Extension/Extensions/SwaggerGenOptionsExtensions.cs

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,47 @@
66
using Swashbuckle.AspNetCore.SwaggerGen;
77

88
// ReSharper disable once CheckNamespace
9-
namespace Swashbuckle.Servers.Extension
9+
#pragma warning disable IDE0130 // Namespace does not match folder structure
10+
namespace Swashbuckle.Servers.Extension;
11+
#pragma warning restore IDE0130 // Namespace does not match folder structure
12+
13+
public static class SwaggerGenOptionsExtensions
1014
{
11-
public static class SwaggerGenOptionsExtensions
15+
public static SwaggerGenOptions WithServers(this SwaggerGenOptions swaggerGenOptions, Action<ServersOptions> setupAction)
1216
{
13-
public static SwaggerGenOptions WithServers(this SwaggerGenOptions swaggerGenOptions, Action<ServersOptions> setupAction)
14-
{
15-
var options = new ServersOptions();
17+
var options = new ServersOptions();
1618

17-
setupAction.Invoke(options);
19+
setupAction.Invoke(options);
1820

19-
swaggerGenOptions.AddOrUpdate(options);
21+
swaggerGenOptions.AddOrUpdate(options);
2022

21-
return swaggerGenOptions;
22-
}
23+
return swaggerGenOptions;
24+
}
2325

24-
public static SwaggerGenOptions WithServers(this SwaggerGenOptions swaggerGenOptions, IEnumerable<OpenApiServer> servers)
25-
{
26-
var options = new ServersOptions { Servers = servers };
26+
public static SwaggerGenOptions WithServers(this SwaggerGenOptions swaggerGenOptions, IEnumerable<OpenApiServer> servers)
27+
{
28+
var options = new ServersOptions { Servers = servers };
2729

28-
swaggerGenOptions.AddOrUpdate(options);
30+
swaggerGenOptions.AddOrUpdate(options);
2931

30-
return swaggerGenOptions;
31-
}
32+
return swaggerGenOptions;
33+
}
34+
35+
private static void AddOrUpdate(this SwaggerGenOptions swaggerGenOptions, ServersOptions options)
36+
{
37+
var filter = swaggerGenOptions
38+
.DocumentFilterDescriptors
39+
.Find(x => x.Type == typeof(ServersDocumentFilter));
3240

33-
private static void AddOrUpdate(this SwaggerGenOptions swaggerGenOptions, ServersOptions options)
41+
if (filter != null)
42+
{
43+
var existingOptions = (ServersOptions) filter.Arguments[0];
44+
45+
existingOptions.Servers = existingOptions.Servers.Concat(options.Servers);
46+
}
47+
else
3448
{
35-
var filter = swaggerGenOptions
36-
.DocumentFilterDescriptors
37-
.Find(x => x.Type == typeof(ServersDocumentFilter));
38-
39-
if (filter != null)
40-
{
41-
var existingOptions = (ServersOptions) filter.Arguments[0];
42-
43-
existingOptions.Servers = existingOptions.Servers.Concat(options.Servers);
44-
}
45-
else
46-
{
47-
swaggerGenOptions.DocumentFilter<ServersDocumentFilter>(options);
48-
}
49+
swaggerGenOptions.DocumentFilter<ServersDocumentFilter>(options);
4950
}
5051
}
5152
}

Swashbuckle.Servers.Extension/Options/ServersOptions.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
using Microsoft.OpenApi;
33

44
// ReSharper disable once CheckNamespace
5-
namespace Swashbuckle.Servers.Extension
5+
namespace Swashbuckle.Servers.Extension;
6+
7+
public class ServersOptions
68
{
7-
public class ServersOptions
8-
{
9-
public IEnumerable<OpenApiServer> Servers { get; set; }
10-
}
9+
public IEnumerable<OpenApiServer> Servers { get; set; }
1110
}

Swashbuckle.Servers.Extension/ServersDocumentFilter.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,12 @@
22
using Microsoft.OpenApi;
33
using Swashbuckle.AspNetCore.SwaggerGen;
44

5-
namespace Swashbuckle.Servers.Extension
5+
namespace Swashbuckle.Servers.Extension;
6+
7+
internal class ServersDocumentFilter(ServersOptions options) : IDocumentFilter
68
{
7-
internal class ServersDocumentFilter : IDocumentFilter
9+
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
810
{
9-
private readonly ServersOptions _options;
10-
11-
public ServersDocumentFilter(ServersOptions options)
12-
{
13-
_options = options;
14-
}
15-
16-
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
17-
{
18-
swaggerDoc.Servers = _options?.Servers?.ToList();
19-
}
11+
swaggerDoc.Servers = options?.Servers?.ToList();
2012
}
2113
}
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
5-
<Authors>Will Axtell</Authors>
6-
<Description>Include a collection of servers in your OAS</Description>
7-
<PackageProjectUrl>https://github.com/waxtell/Swashbuckle.Servers.Extension</PackageProjectUrl>
8-
<RepositoryUrl>https://github.com/waxtell/Swashbuckle.Servers.Extension.git</RepositoryUrl>
9-
<RepositoryType>git</RepositoryType>
10-
<PackageTags>OAS Swashbuckle Servers</PackageTags>
11-
<PackageReleaseNotes>
12-
1.1.0 - Upgrade to .NET 8.0 and Swashbuckle.AspNetCore v10.1.0
13-
1.0.3 - Add WithVariable extension
14-
1.0.2 - Now supports multiple, concatenating invocations
15-
1.0.1 - Initial release
16-
</PackageReleaseNotes>
17-
<VersionPrefix>1.1.0</VersionPrefix>
18-
</PropertyGroup>
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Authors>Will Axtell</Authors>
6+
<Description>Include a collection of servers in your OAS</Description>
7+
<PackageProjectUrl>https://github.com/waxtell/Swashbuckle.Servers.Extension</PackageProjectUrl>
8+
<RepositoryUrl>https://github.com/waxtell/Swashbuckle.Servers.Extension.git</RepositoryUrl>
9+
<RepositoryType>git</RepositoryType>
10+
<PackageTags>OAS Swashbuckle Servers</PackageTags>
11+
<PackageReleaseNotes>
12+
1.1.0 - Upgrade to .NET 8.0 and Swashbuckle.AspNetCore v10.1.0
13+
1.0.3 - Add WithVariable extension
14+
1.0.2 - Now supports multiple, concatenating invocations
15+
1.0.1 - Initial release
16+
</PackageReleaseNotes>
17+
<VersionPrefix>1.1.0</VersionPrefix>
18+
</PropertyGroup>
1919

20-
<ItemGroup>
21-
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.0" />
22-
</ItemGroup>
20+
<ItemGroup>
21+
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.0" />
22+
</ItemGroup>
2323

2424
</Project>

0 commit comments

Comments
 (0)