diff --git a/src/Swashbuckle.AspNetCore.ReDoc/Swashbuckle.AspNetCore.ReDoc.csproj b/src/Swashbuckle.AspNetCore.ReDoc/Swashbuckle.AspNetCore.ReDoc.csproj
index 90efe41080..ab861e7bf2 100644
--- a/src/Swashbuckle.AspNetCore.ReDoc/Swashbuckle.AspNetCore.ReDoc.csproj
+++ b/src/Swashbuckle.AspNetCore.ReDoc/Swashbuckle.AspNetCore.ReDoc.csproj
@@ -26,7 +26,7 @@
-
+
diff --git a/src/Swashbuckle.AspNetCore.Swagger/SwaggerMiddleware.cs b/src/Swashbuckle.AspNetCore.Swagger/SwaggerMiddleware.cs
index 0ef11d7559..d6e745daff 100644
--- a/src/Swashbuckle.AspNetCore.Swagger/SwaggerMiddleware.cs
+++ b/src/Swashbuckle.AspNetCore.Swagger/SwaggerMiddleware.cs
@@ -30,7 +30,7 @@ public SwaggerMiddleware(
{
_next = next;
_options = options ?? new SwaggerOptions();
- _requestMatcher = new TemplateMatcher(TemplateParser.Parse(_options.RouteTemplate), new RouteValueDictionary());
+ _requestMatcher = new TemplateMatcher(TemplateParser.Parse(_options.RouteTemplate), []);
}
#if !NETSTANDARD
diff --git a/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIJsonSerializerContext.cs b/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIJsonSerializerContext.cs
index ed15c9df84..72e175fb6e 100644
--- a/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIJsonSerializerContext.cs
+++ b/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIJsonSerializerContext.cs
@@ -1,4 +1,7 @@
#if NET6_0_OR_GREATER
+using System;
+using System.Text.Json;
+using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
namespace Swashbuckle.AspNetCore.SwaggerUI;
@@ -6,6 +9,36 @@ namespace Swashbuckle.AspNetCore.SwaggerUI;
[JsonSerializable(typeof(ConfigObject))]
[JsonSerializable(typeof(InterceptorFunctions))]
[JsonSerializable(typeof(OAuthConfigObject))]
+// These primitive types are declared for common types that may be used with ConfigObject.AdditionalItems. See https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/2884.
+[JsonSerializable(typeof(bool))]
+[JsonSerializable(typeof(byte))]
+[JsonSerializable(typeof(sbyte))]
+[JsonSerializable(typeof(short))]
+[JsonSerializable(typeof(ushort))]
+[JsonSerializable(typeof(int))]
+[JsonSerializable(typeof(uint))]
+[JsonSerializable(typeof(long))]
+[JsonSerializable(typeof(ulong))]
+[JsonSerializable(typeof(float))]
+[JsonSerializable(typeof(double))]
+[JsonSerializable(typeof(decimal))]
+[JsonSerializable(typeof(char))]
+[JsonSerializable(typeof(string))]
+[JsonSerializable(typeof(DateTime))]
+[JsonSerializable(typeof(DateTimeOffset))]
+[JsonSerializable(typeof(TimeSpan))]
+[JsonSerializable(typeof(JsonArray))]
+[JsonSerializable(typeof(JsonObject))]
+[JsonSerializable(typeof(JsonDocument))]
+#if NET7_0_OR_GREATER
+[JsonSerializable(typeof(DateOnly))]
+[JsonSerializable(typeof(TimeOnly))]
+#endif
+#if NET8_0_OR_GREATER
+[JsonSerializable(typeof(Half))]
+[JsonSerializable(typeof(Int128))]
+[JsonSerializable(typeof(UInt128))]
+#endif
[JsonSourceGenerationOptions(
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)]
diff --git a/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIMiddleware.cs b/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIMiddleware.cs
index 52dac4b73e..0b3ae62bbe 100644
--- a/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIMiddleware.cs
+++ b/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIMiddleware.cs
@@ -89,7 +89,7 @@ public async Task Invoke(HttpContext httpContext)
await _staticFileMiddleware.Invoke(httpContext);
}
- private StaticFileMiddleware CreateStaticFileMiddleware(
+ private static StaticFileMiddleware CreateStaticFileMiddleware(
RequestDelegate next,
IWebHostEnvironment hostingEnv,
ILoggerFactory loggerFactory,
@@ -104,7 +104,7 @@ private StaticFileMiddleware CreateStaticFileMiddleware(
return new StaticFileMiddleware(next, hostingEnv, Options.Create(staticFileOptions), loggerFactory);
}
- private void RespondWithRedirect(HttpResponse response, string location)
+ private static void RespondWithRedirect(HttpResponse response, string location)
{
response.StatusCode = 301;
response.Headers["Location"] = location;
diff --git a/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIOptions.cs b/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIOptions.cs
index cd9aa9df42..f4140ec572 100644
--- a/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIOptions.cs
+++ b/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIOptions.cs
@@ -162,7 +162,7 @@ public class ConfigObject
public string ValidatorUrl { get; set; } = null;
[JsonExtensionData]
- public Dictionary AdditionalItems { get; set; } = new Dictionary();
+ public Dictionary AdditionalItems { get; set; } = [];
}
public class UrlDescriptor
@@ -233,7 +233,7 @@ public class OAuthConfigObject
///
/// String array of initially selected oauth scopes, default is empty array
///
- public IEnumerable Scopes { get; set; } = new string[] { };
+ public IEnumerable Scopes { get; set; } = [];
///
/// Additional query parameters added to authorizationUrl and tokenUrl
diff --git a/src/Swashbuckle.AspNetCore.SwaggerUI/Swashbuckle.AspNetCore.SwaggerUI.csproj b/src/Swashbuckle.AspNetCore.SwaggerUI/Swashbuckle.AspNetCore.SwaggerUI.csproj
index 3e3a285f7b..10d562b646 100644
--- a/src/Swashbuckle.AspNetCore.SwaggerUI/Swashbuckle.AspNetCore.SwaggerUI.csproj
+++ b/src/Swashbuckle.AspNetCore.SwaggerUI/Swashbuckle.AspNetCore.SwaggerUI.csproj
@@ -30,7 +30,7 @@
-
+
diff --git a/test/WebSites/CustomUIConfig/Startup.cs b/test/WebSites/CustomUIConfig/Startup.cs
index 9a86e2dced..abfefe10dc 100644
--- a/test/WebSites/CustomUIConfig/Startup.cs
+++ b/test/WebSites/CustomUIConfig/Startup.cs
@@ -1,9 +1,11 @@
+using System;
+using System.Text.Json;
+using System.Text.Json.Nodes;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
-using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerUI;
namespace CustomUIConfig
@@ -76,6 +78,34 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
c.UseResponseInterceptor("(res) => { console.log('Custom interceptor intercepted response from:', res.url); return res; }");
c.EnablePersistAuthorization();
+ c.ConfigObject.AdditionalItems.Add("syntaxHighlight", false);
+ c.ConfigObject.AdditionalItems.Add("charProperty", 'c');
+ c.ConfigObject.AdditionalItems.Add("stringProperty", "value");
+ c.ConfigObject.AdditionalItems.Add("byteProperty", (byte)1);
+ c.ConfigObject.AdditionalItems.Add("signedByteProperty", (sbyte)1);
+ c.ConfigObject.AdditionalItems.Add("int16Property", (short)1);
+ c.ConfigObject.AdditionalItems.Add("uint16Property", (ushort)1);
+ c.ConfigObject.AdditionalItems.Add("int32Property", 1);
+ c.ConfigObject.AdditionalItems.Add("uint32Property", 1u);
+ c.ConfigObject.AdditionalItems.Add("int64Property", 1L);
+ c.ConfigObject.AdditionalItems.Add("uint64Property", 1uL);
+ c.ConfigObject.AdditionalItems.Add("floatProperty", 1f);
+ c.ConfigObject.AdditionalItems.Add("doubleProperty", 1d);
+ c.ConfigObject.AdditionalItems.Add("decimalProperty", 1m);
+ c.ConfigObject.AdditionalItems.Add("dateTimeProperty", DateTime.UtcNow);
+ c.ConfigObject.AdditionalItems.Add("dateTimeOffsetProperty", DateTimeOffset.UtcNow);
+ c.ConfigObject.AdditionalItems.Add("timeSpanProperty", new TimeSpan(12, 34, 56));
+ c.ConfigObject.AdditionalItems.Add("jsonArray", new JsonArray() { "string" });
+ c.ConfigObject.AdditionalItems.Add("jsonObject", new JsonObject() { ["foo"] = "bar" });
+ c.ConfigObject.AdditionalItems.Add("jsonDocument", JsonDocument.Parse("""{ "foo": "bar" }"""));
+
+#if NET8_0_OR_GREATER
+ c.ConfigObject.AdditionalItems.Add("dateOnlyProperty", new DateOnly(1977, 05, 25));
+ c.ConfigObject.AdditionalItems.Add("timeOnlyProperty", new TimeOnly(12, 34, 56));
+ c.ConfigObject.AdditionalItems.Add("halfProperty", Half.CreateChecked(1));
+ c.ConfigObject.AdditionalItems.Add("int128Property", Int128.CreateChecked(1));
+ c.ConfigObject.AdditionalItems.Add("unt128Property", UInt128.CreateChecked(1));
+#endif
});
}
}