Skip to content

Commit d3b910c

Browse files
authored
Merge pull request #5 from Scott-transtar/develop
Upgrade to .NET 8.0 and Swashbuckle.AspNetCore v10.1.0; update workfl…
2 parents 1cf2a07 + d7d656e commit d3b910c

File tree

11 files changed

+90
-97
lines changed

11 files changed

+90
-97
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ jobs:
88
runs-on: ubuntu-latest
99

1010
steps:
11-
- uses: actions/checkout@v1
11+
- uses: actions/checkout@v4
1212
- name: Setup .NET Core
13-
uses: actions/setup-dotnet@v1
13+
uses: actions/setup-dotnet@v4
1414
with:
15-
dotnet-version: 7.0.x
15+
dotnet-version: 9.0.x
1616
- name: Build with dotnet
1717
run: dotnet build --configuration Release

.github/workflows/publishtonuget.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
name: publish to nuget
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v1
11+
- uses: actions/checkout@v4
1212

1313
# Publish
1414
- name: Publish NuGet

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/SampleApp9000.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
6+
<NoWarn>NU1900</NoWarn>
57
</PropertyGroup>
68

79
<ItemGroup>

SampleApp9000/Startup.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Microsoft.AspNetCore.Builder;
22
using Microsoft.AspNetCore.Hosting;
3-
using Microsoft.OpenApi.Models;
4-
using Microsoft.Extensions.Configuration;
3+
using Microsoft.OpenApi;
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>
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
using Microsoft.OpenApi.Models;
1+
using System;
2+
using System.Collections.Generic;
3+
using Microsoft.OpenApi;
24

3-
namespace Swashbuckle.Servers.Extension.Extensions
5+
namespace Swashbuckle.Servers.Extension.Extensions;
6+
7+
public static class OpenApiServerExtensions
48
{
5-
public static class OpenApiServerExtensions
9+
public static OpenApiServer WithVariable(this OpenApiServer server, string key, OpenApiServerVariable value)
610
{
7-
public static OpenApiServer WithVariable(this OpenApiServer server, string key, OpenApiServerVariable value)
8-
{
9-
server.Variables.Add(key, value);
11+
ArgumentNullException.ThrowIfNull(server);
12+
13+
server.Variables ??= new Dictionary<string, OpenApiServerVariable>();
14+
server.Variables.Add(key, value);
1015

11-
return server;
12-
}
16+
return server;
1317
}
1418
}

Swashbuckle.Servers.Extension/Extensions/SwaggerGenOptionsExtensions.cs

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,51 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using Microsoft.Extensions.DependencyInjection;
5-
using Microsoft.OpenApi.Models;
5+
using Microsoft.OpenApi;
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
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
using System.Collections.Generic;
2-
using Microsoft.OpenApi.Models;
2+
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
}
Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
using System.Linq;
2-
using Microsoft.OpenApi.Models;
2+
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
}

0 commit comments

Comments
 (0)