diff --git a/README.md b/README.md index 9a86d8edac..210341285e 100644 --- a/README.md +++ b/README.md @@ -115,6 +115,20 @@ In versions of Swashbuckle.AspNetCore prior to `5.0.0`, Swashbuckle would genera on the behavior of the [Newtonsoft.Json serializer][newtonsoft-json]. This made sense because that was the serializer that shipped with ASP.NET Core at the time. However, since ASP.NET Core 3.0, ASP.NET Core introduces a new serializer, [System.Text.Json (STJ)][system-text-json] out-of-the-box. +If you find that the *STJ* options/attributes are not being honored, this may be because you are using a combination of Minimal APIs and MVC, which have separate JSON options. +To force the OpenAPI document generation to use either set of JSON options you can use one of the following methods: + +```csharp +services.AddSwaggerGen(c => +{ + c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" }); +}); +// Then either: +services.AddSwaggerGenMinimalApisJsonOptions(); +// or ... +services.AddSwaggerGenMvcJsonOptions(); +``` + If you want to use Newtonsoft.Json instead, you need to install a separate package and explicitly opt-in. By default Swashbuckle.AspNetCore will assume you're using the System.Text.Json serializer and generate Schemas based on its behavior. If you're using Newtonsoft.Json then you'll need to install a separate Swashbuckle package, [Swashbuckle.AspNetCore.Newtonsoft][swashbuckle-aspnetcore-newtonsoft] to explicitly opt-in. diff --git a/src/Swashbuckle.AspNetCore.SwaggerGen/DependencyInjection/ConfigureMinimalApiSwaggerGenJsonOptions.cs b/src/Swashbuckle.AspNetCore.SwaggerGen/DependencyInjection/ConfigureMinimalApiSwaggerGenJsonOptions.cs new file mode 100644 index 0000000000..0e6e3fa67e --- /dev/null +++ b/src/Swashbuckle.AspNetCore.SwaggerGen/DependencyInjection/ConfigureMinimalApiSwaggerGenJsonOptions.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Http.Json; +using Microsoft.Extensions.Options; + +namespace Swashbuckle.AspNetCore.SwaggerGen.DependencyInjection; + +internal sealed class ConfigureMinimalApiSwaggerGenJsonOptions(IOptions jsonOptions) : IConfigureOptions +{ + public void Configure(SwaggerGenJsonOptions options) + { + options.SerializerOptions = jsonOptions.Value.SerializerOptions; + } +} diff --git a/src/Swashbuckle.AspNetCore.SwaggerGen/DependencyInjection/ConfigureMvcSwaggerGenJsonOptions.cs b/src/Swashbuckle.AspNetCore.SwaggerGen/DependencyInjection/ConfigureMvcSwaggerGenJsonOptions.cs new file mode 100644 index 0000000000..1d9d3ea0d2 --- /dev/null +++ b/src/Swashbuckle.AspNetCore.SwaggerGen/DependencyInjection/ConfigureMvcSwaggerGenJsonOptions.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; + +namespace Swashbuckle.AspNetCore.SwaggerGen.DependencyInjection; + +internal sealed class ConfigureMvcSwaggerGenJsonOptions(IOptions jsonOptions) : IConfigureOptions +{ + public void Configure(SwaggerGenJsonOptions options) + { + options.SerializerOptions = jsonOptions.Value.JsonSerializerOptions; + } +} diff --git a/src/Swashbuckle.AspNetCore.SwaggerGen/DependencyInjection/ConfigureSwaggerGenJsonOptions.cs b/src/Swashbuckle.AspNetCore.SwaggerGen/DependencyInjection/ConfigureSwaggerGenJsonOptions.cs new file mode 100644 index 0000000000..5a84186f74 --- /dev/null +++ b/src/Swashbuckle.AspNetCore.SwaggerGen/DependencyInjection/ConfigureSwaggerGenJsonOptions.cs @@ -0,0 +1,53 @@ +using System.Text.Json; +using Microsoft.Extensions.Options; + +namespace Swashbuckle.AspNetCore.SwaggerGen.DependencyInjection; + +internal sealed class ConfigureSwaggerGenJsonOptions : IPostConfigureOptions +{ + private readonly IEnumerable> _minimalApiConfigureOptions; + private readonly IEnumerable> _minimalApiPostConfigureOptions; + private readonly Microsoft.AspNetCore.Http.Json.JsonOptions _minimalApiJsonOptions; + private readonly Microsoft.AspNetCore.Mvc.JsonOptions _mvcJsonOptions; + + public ConfigureSwaggerGenJsonOptions( + IEnumerable> minimalApiConfigureOptions, + IEnumerable> minimalApiPostConfigureOptions, + IOptions minimalApiJsonOptions, + IOptions mvcJsonOptions) + { + _minimalApiConfigureOptions = minimalApiConfigureOptions; + _minimalApiPostConfigureOptions = minimalApiPostConfigureOptions; + _minimalApiJsonOptions = minimalApiJsonOptions.Value; + _mvcJsonOptions = mvcJsonOptions.Value; + } + + public void PostConfigure(string name, SwaggerGenJsonOptions options) + { + if (options.SerializerOptions != null) + { + return; + } + + /* + * There is no surefire way to do this. + * However, both JsonOptions are defaulted in the same way. + * If neither is configured it makes no difference which one is chosen. + * If both are configured, then we just need to make a choice. + * As Minimal APIs are newer if someone is configuring them + * it's probably more likely that is what they're using. + * + * If either JsonOptions is null we will try to create a new instance as + * a last resort as this is an expensive operation. + */ + + var serializerOptions = _mvcJsonOptions.JsonSerializerOptions; + + if (_minimalApiConfigureOptions.Any() || _minimalApiPostConfigureOptions.Any()) + { + serializerOptions = _minimalApiJsonOptions.SerializerOptions; + } + + options.SerializerOptions = serializerOptions; + } +} diff --git a/src/Swashbuckle.AspNetCore.SwaggerGen/DependencyInjection/SwaggerGenJsonOptions.cs b/src/Swashbuckle.AspNetCore.SwaggerGen/DependencyInjection/SwaggerGenJsonOptions.cs new file mode 100644 index 0000000000..f98352bacc --- /dev/null +++ b/src/Swashbuckle.AspNetCore.SwaggerGen/DependencyInjection/SwaggerGenJsonOptions.cs @@ -0,0 +1,14 @@ +using System.Text.Json; + +namespace Swashbuckle.AspNetCore.SwaggerGen.DependencyInjection; + +/// +/// Configures the to be used by . +/// +public class SwaggerGenJsonOptions +{ + /// + /// Gets or sets the JSON serializer options to use. + /// + public JsonSerializerOptions SerializerOptions { get; set; } +} diff --git a/src/Swashbuckle.AspNetCore.SwaggerGen/DependencyInjection/SwaggerGenServiceCollectionExtensions.cs b/src/Swashbuckle.AspNetCore.SwaggerGen/DependencyInjection/SwaggerGenServiceCollectionExtensions.cs index bcbfc82a7e..83556de385 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerGen/DependencyInjection/SwaggerGenServiceCollectionExtensions.cs +++ b/src/Swashbuckle.AspNetCore.SwaggerGen/DependencyInjection/SwaggerGenServiceCollectionExtensions.cs @@ -1,9 +1,9 @@ -using System.Text.Json; -using Microsoft.Extensions.ApiDescriptions; +using Microsoft.Extensions.ApiDescriptions; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Options; using Swashbuckle.AspNetCore.Swagger; using Swashbuckle.AspNetCore.SwaggerGen; +using Swashbuckle.AspNetCore.SwaggerGen.DependencyInjection; namespace Microsoft.Extensions.DependencyInjection; @@ -29,10 +29,10 @@ public static IServiceCollection AddSwaggerGen( services.TryAddTransient(s => s.GetRequiredService>().Value); services.TryAddTransient(); services.TryAddTransient(s => s.GetRequiredService>().Value); - services.AddSingleton(); + services.ConfigureOptions(); services.TryAddSingleton(s => { - var serializerOptions = s.GetRequiredService().Options; + var serializerOptions = s.GetRequiredService>().Value.SerializerOptions; return new JsonSerializerDataContractResolver(serializerOptions); }); @@ -44,41 +44,20 @@ public static IServiceCollection AddSwaggerGen( return services; } - public static void ConfigureSwaggerGen( - this IServiceCollection services, - Action setupAction) + public static IServiceCollection AddSwaggerGenMinimalApisJsonOptions(this IServiceCollection services) { - services.Configure(setupAction); + return services.ConfigureOptions(); } - private sealed class JsonSerializerOptionsProvider + public static IServiceCollection AddSwaggerGenMvcJsonOptions(this IServiceCollection services) { - private JsonSerializerOptions _options; - private readonly IServiceProvider _serviceProvider; - - public JsonSerializerOptionsProvider(IServiceProvider serviceProvider) - { - _serviceProvider = serviceProvider; - } - - public JsonSerializerOptions Options => _options ??= ResolveOptions(); - - private JsonSerializerOptions ResolveOptions() - { - JsonSerializerOptions serializerOptions; - - /* - * First try to get the options configured for MVC, - * then try to get the options configured for Minimal APIs if available, - * then try the default JsonSerializerOptions if available, - * otherwise create a new instance as a last resort as this is an expensive operation. - */ - serializerOptions = - _serviceProvider.GetService>()?.Value?.JsonSerializerOptions - ?? _serviceProvider.GetService>()?.Value?.SerializerOptions - ?? JsonSerializerOptions.Default; + return services.ConfigureOptions(); + } - return serializerOptions; - } + public static void ConfigureSwaggerGen( + this IServiceCollection services, + Action setupAction) + { + services.Configure(setupAction); } } diff --git a/src/Swashbuckle.AspNetCore.SwaggerGen/PublicAPI/PublicAPI.Unshipped.txt b/src/Swashbuckle.AspNetCore.SwaggerGen/PublicAPI/PublicAPI.Unshipped.txt index e69de29bb2..17ed50dfe2 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerGen/PublicAPI/PublicAPI.Unshipped.txt +++ b/src/Swashbuckle.AspNetCore.SwaggerGen/PublicAPI/PublicAPI.Unshipped.txt @@ -0,0 +1,4 @@ +Swashbuckle.AspNetCore.SwaggerGen.DependencyInjection.SwaggerGenJsonOptions +Swashbuckle.AspNetCore.SwaggerGen.DependencyInjection.SwaggerGenJsonOptions.SerializerOptions.get -> System.Text.Json.JsonSerializerOptions +Swashbuckle.AspNetCore.SwaggerGen.DependencyInjection.SwaggerGenJsonOptions.SerializerOptions.set -> void +Swashbuckle.AspNetCore.SwaggerGen.DependencyInjection.SwaggerGenJsonOptions.SwaggerGenJsonOptions() -> void diff --git a/src/Swashbuckle.AspNetCore.SwaggerGen/PublicAPI/net8.0/PublicAPI.Unshipped.txt b/src/Swashbuckle.AspNetCore.SwaggerGen/PublicAPI/net8.0/PublicAPI.Unshipped.txt index 5f282702bb..fc2380cbac 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerGen/PublicAPI/net8.0/PublicAPI.Unshipped.txt +++ b/src/Swashbuckle.AspNetCore.SwaggerGen/PublicAPI/net8.0/PublicAPI.Unshipped.txt @@ -1 +1,2 @@ - \ No newline at end of file +static Microsoft.Extensions.DependencyInjection.SwaggerGenServiceCollectionExtensions.AddSwaggerGenMinimalApisJsonOptions(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection +static Microsoft.Extensions.DependencyInjection.SwaggerGenServiceCollectionExtensions.AddSwaggerGenMvcJsonOptions(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection diff --git a/src/Swashbuckle.AspNetCore.SwaggerGen/PublicAPI/net9.0/PublicAPI.Unshipped.txt b/src/Swashbuckle.AspNetCore.SwaggerGen/PublicAPI/net9.0/PublicAPI.Unshipped.txt index 5f282702bb..fc2380cbac 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerGen/PublicAPI/net9.0/PublicAPI.Unshipped.txt +++ b/src/Swashbuckle.AspNetCore.SwaggerGen/PublicAPI/net9.0/PublicAPI.Unshipped.txt @@ -1 +1,2 @@ - \ No newline at end of file +static Microsoft.Extensions.DependencyInjection.SwaggerGenServiceCollectionExtensions.AddSwaggerGenMinimalApisJsonOptions(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection +static Microsoft.Extensions.DependencyInjection.SwaggerGenServiceCollectionExtensions.AddSwaggerGenMvcJsonOptions(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=WebApi.Program_swaggerRequestUri=v1.DotNet8_0.verified.txt b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=WebApi.Program_swaggerRequestUri=v1.DotNet8_0.verified.txt index d437eea1cf..176304b23b 100644 --- a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=WebApi.Program_swaggerRequestUri=v1.DotNet8_0.verified.txt +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=WebApi.Program_swaggerRequestUri=v1.DotNet8_0.verified.txt @@ -988,12 +988,11 @@ }, "DateTimeKind": { "enum": [ - 0, - 1, - 2 + "Unspecified", + "Utc", + "Local" ], - "type": "integer", - "format": "int32" + "type": "string" }, "Fruit": { "type": "object", diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=WebApi.Program_swaggerRequestUri=v1.DotNet9_0.verified.txt b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=WebApi.Program_swaggerRequestUri=v1.DotNet9_0.verified.txt index d437eea1cf..176304b23b 100644 --- a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=WebApi.Program_swaggerRequestUri=v1.DotNet9_0.verified.txt +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=WebApi.Program_swaggerRequestUri=v1.DotNet9_0.verified.txt @@ -988,12 +988,11 @@ }, "DateTimeKind": { "enum": [ - 0, - 1, - 2 + "Unspecified", + "Utc", + "Local" ], - "type": "integer", - "format": "int32" + "type": "string" }, "Fruit": { "type": "object", diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.TypesAreRenderedCorrectly.DotNet8_0.verified.txt b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.TypesAreRenderedCorrectly.DotNet8_0.verified.txt index d437eea1cf..176304b23b 100644 --- a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.TypesAreRenderedCorrectly.DotNet8_0.verified.txt +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.TypesAreRenderedCorrectly.DotNet8_0.verified.txt @@ -988,12 +988,11 @@ }, "DateTimeKind": { "enum": [ - 0, - 1, - 2 + "Unspecified", + "Utc", + "Local" ], - "type": "integer", - "format": "int32" + "type": "string" }, "Fruit": { "type": "object", diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.TypesAreRenderedCorrectly.DotNet9_0.verified.txt b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.TypesAreRenderedCorrectly.DotNet9_0.verified.txt index d437eea1cf..176304b23b 100644 --- a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.TypesAreRenderedCorrectly.DotNet9_0.verified.txt +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.TypesAreRenderedCorrectly.DotNet9_0.verified.txt @@ -988,12 +988,11 @@ }, "DateTimeKind": { "enum": [ - 0, - 1, - 2 + "Unspecified", + "Utc", + "Local" ], - "type": "integer", - "format": "int32" + "type": "string" }, "Fruit": { "type": "object", diff --git a/test/Swashbuckle.AspNetCore.SwaggerGen.Test/Fixtures/DummyHostEnvironment.cs b/test/Swashbuckle.AspNetCore.SwaggerGen.Test/Fixtures/DummyHostEnvironment.cs new file mode 100644 index 0000000000..40b2ae70b4 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.SwaggerGen.Test/Fixtures/DummyHostEnvironment.cs @@ -0,0 +1,14 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.FileProviders; + +namespace Swashbuckle.AspNetCore.SwaggerGen.Test.Fixtures; + +internal sealed class DummyHostEnvironment : IWebHostEnvironment +{ + public string WebRootPath { get; set; } + public IFileProvider WebRootFileProvider { get; set; } + public string ApplicationName { get; set; } + public IFileProvider ContentRootFileProvider { get; set; } + public string ContentRootPath { get; set; } + public string EnvironmentName { get; set; } +} diff --git a/test/Swashbuckle.AspNetCore.SwaggerGen.Test/SwaggerGenJsonOptionsTests.cs b/test/Swashbuckle.AspNetCore.SwaggerGen.Test/SwaggerGenJsonOptionsTests.cs new file mode 100644 index 0000000000..cb4c76ec81 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.SwaggerGen.Test/SwaggerGenJsonOptionsTests.cs @@ -0,0 +1,78 @@ +using System.Text.Json; +using System.Text.Json.Serialization; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; +using Swashbuckle.AspNetCore.SwaggerGen.DependencyInjection; +using Swashbuckle.AspNetCore.SwaggerGen.Test.Fixtures; + +using MinimalApiJsonOptions = Microsoft.AspNetCore.Http.Json.JsonOptions; +using MvcJsonOptions = Microsoft.AspNetCore.Mvc.JsonOptions; + +namespace Swashbuckle.AspNetCore.SwaggerGen.Test; + +public class SwaggerGenJsonOptionsTests +{ + [Fact] + public static void Ensure_SwaggerGenJsonOptions_Uses_MinimalApi_JsonOptions_When_Overridden() + { + var services = new ServiceCollection(); + services.AddSingleton(); + services.AddSwaggerGen(); + services.AddMvcCore().AddJsonOptions(o => o.JsonSerializerOptions.AllowTrailingCommas = true); + services.AddSwaggerGenMinimalApisJsonOptions(); + + using var provider = services.BuildServiceProvider(); + + var minimalApiJsonOptions = provider.GetService>().Value.SerializerOptions; + var swaggerGenSerializerOptions = provider.GetService>().Value.SerializerOptions; + Assert.Equal(minimalApiJsonOptions, swaggerGenSerializerOptions); + } + + [Fact] + public static void Ensure_SwaggerGenJsonOptions_Uses_Mvc_JsonOptions_When_Overridden() + { + var services = new ServiceCollection(); + services.AddSingleton(); + services.AddSwaggerGen(); + services.ConfigureHttpJsonOptions(o => o.SerializerOptions.AllowTrailingCommas = true); + services.AddSwaggerGenMvcJsonOptions(); + + using var provider = services.BuildServiceProvider(); + + var mvcJsonOptions = provider.GetService>().Value.JsonSerializerOptions; + var swaggerGenSerializerOptions = provider.GetService>().Value.SerializerOptions; + Assert.Equal(mvcJsonOptions, swaggerGenSerializerOptions); + } + + [Fact] + public static void Ensure_SwaggerGenJsonOptions_Uses_Mvc_JsonOptions_When_Not_Using_Minimal_Apis() + { + var services = new ServiceCollection(); + services.AddSingleton(); + services.AddSwaggerGen(); + services.AddMvcCore().AddJsonOptions(o => o.JsonSerializerOptions.AllowTrailingCommas = true); + + using var provider = services.BuildServiceProvider(); + + var mvcJsonOptions = provider.GetService>().Value.JsonSerializerOptions; + var swaggerGenSerializerOptions = provider.GetService>().Value.SerializerOptions; + Assert.Equal(mvcJsonOptions, swaggerGenSerializerOptions); + } + + [Fact] + public static void Ensure_SwaggerGenJsonOptions_Uses_MinimalApi_JsonOptions_When_Configured() + { + var services = new ServiceCollection(); + services.AddSingleton(); + services.AddSwaggerGen(); + services.ConfigureHttpJsonOptions(o => o.SerializerOptions.AllowTrailingCommas = true); + services.AddMvcCore().AddJsonOptions(o => o.JsonSerializerOptions.AllowTrailingCommas = true); + + using var provider = services.BuildServiceProvider(); + + var minimalApiJsonOptions = provider.GetService>().Value.SerializerOptions; + var swaggerGenSerializerOptions = provider.GetService>().Value.SerializerOptions; + Assert.Equal(minimalApiJsonOptions, swaggerGenSerializerOptions); + } +} diff --git a/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsDocumentFilterTests.cs b/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsDocumentFilterTests.cs index 54602b782f..bc16a39135 100644 --- a/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsDocumentFilterTests.cs +++ b/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsDocumentFilterTests.cs @@ -4,8 +4,8 @@ using Microsoft.AspNetCore.Mvc.ApiExplorer; using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.FileProviders; using Microsoft.OpenApi.Models; +using Swashbuckle.AspNetCore.SwaggerGen.Test.Fixtures; namespace Swashbuckle.AspNetCore.SwaggerGen.Test; @@ -179,14 +179,4 @@ public void Ensure_IncludeXmlComments_Adds_Filter_To_Options() Assert.NotNull(options); Assert.Contains(options.DocumentFilters, x => x is XmlCommentsDocumentFilter); } - - private sealed class DummyHostEnvironment : IWebHostEnvironment - { - public string WebRootPath { get; set; } - public IFileProvider WebRootFileProvider { get; set; } - public string ApplicationName { get; set; } - public IFileProvider ContentRootFileProvider { get; set; } - public string ContentRootPath { get; set; } - public string EnvironmentName { get; set; } - } } diff --git a/test/WebSites/Basic/Startup.cs b/test/WebSites/Basic/Startup.cs index ba8ce11df0..2dad12c0b0 100644 --- a/test/WebSites/Basic/Startup.cs +++ b/test/WebSites/Basic/Startup.cs @@ -42,6 +42,8 @@ public void ConfigureServices(IServiceCollection services) c.EnableAnnotations(); }); + + services.AddSwaggerGenMinimalApisJsonOptions(); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) diff --git a/test/WebSites/MinimalAppWithHostedServices/Program.cs b/test/WebSites/MinimalAppWithHostedServices/Program.cs index c0195e5b72..69d490769f 100644 --- a/test/WebSites/MinimalAppWithHostedServices/Program.cs +++ b/test/WebSites/MinimalAppWithHostedServices/Program.cs @@ -6,6 +6,8 @@ c.SwaggerDoc("v1", new() { Title = "MinimalApp", Version = "v1" }); }); +builder.Services.AddSwaggerGenMinimalApisJsonOptions(); + builder.Services.AddHostedService(); var app = builder.Build();