Skip to content

Commit

Permalink
Fix loading of correct JSON serializer options, fixes #4834, regressi…
Browse files Browse the repository at this point in the history
…on of #4733, v14.0.7
  • Loading branch information
RicoSuter committed Mar 26, 2024
1 parent 3e19ef2 commit b3615b4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<VersionPrefix>14.0.6</VersionPrefix>
<VersionPrefix>14.0.7</VersionPrefix>

<Authors>Rico Suter</Authors>
<Copyright>Copyright © Rico Suter, 2023</Copyright>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,25 @@ public static IServiceCollection AddSwaggerDocument(this IServiceCollection serv
var settings = new AspNetCoreOpenApiDocumentGeneratorSettings();
var mvcOptions = services.GetRequiredService<IOptions<MvcOptions>>();
var hasSystemTextJsonOutputFormatter = mvcOptions.Value.OutputFormatters
.Any(f => f.GetType().Name == "SystemTextJsonOutputFormatter");
var newtonsoftSettings = AspNetCoreOpenApiDocumentGenerator.GetJsonSerializerSettings(services);
var systemTextJsonOptions = mvcOptions.Value.OutputFormatters
.Any(f => f.GetType().Name == "SystemTextJsonOutputFormatter")
var systemTextJsonOptions = hasSystemTextJsonOutputFormatter
? AspNetCoreOpenApiDocumentGenerator.GetSystemTextJsonSettings(services)
#if NET6_0_OR_GREATER
: services.GetService<IOptions<Microsoft.AspNetCore.Http.Json.JsonOptions>>()?.Value.SerializerOptions;
: services.GetService<IOptions<AspNetCore.Http.Json.JsonOptions>>()?.Value.SerializerOptions;
#else
: null;
#endif
if (systemTextJsonOptions != null)
{
settings.ApplySettings(new SystemTextJsonSchemaGeneratorSettings { SerializerOptions = systemTextJsonOptions }, mvcOptions.Value);
}
else if (newtonsoftSettings != null)
if (newtonsoftSettings != null && !hasSystemTextJsonOutputFormatter)
{
settings.ApplySettings(new NewtonsoftJsonSchemaGeneratorSettings { SerializerSettings = newtonsoftSettings }, mvcOptions.Value);
}
else if (systemTextJsonOptions != null)
{
settings.ApplySettings(new SystemTextJsonSchemaGeneratorSettings { SerializerOptions = systemTextJsonOptions }, mvcOptions.Value);
}
else
{
Expand Down

0 comments on commit b3615b4

Please sign in to comment.