diff --git a/src/NSwag.AspNetCore/Extensions/NSwagServiceCollectionExtensions.cs b/src/NSwag.AspNetCore/Extensions/NSwagServiceCollectionExtensions.cs index aa33837244..8a1e1484d7 100644 --- a/src/NSwag.AspNetCore/Extensions/NSwagServiceCollectionExtensions.cs +++ b/src/NSwag.AspNetCore/Extensions/NSwagServiceCollectionExtensions.cs @@ -71,8 +71,13 @@ public static IServiceCollection AddSwaggerDocument(this IServiceCollection serv var mvcOptions = services.GetRequiredService>(); var newtonsoftSettings = AspNetCoreOpenApiDocumentGenerator.GetJsonSerializerSettings(services); var systemTextJsonOptions = mvcOptions.Value.OutputFormatters - .Any(f => f.GetType().Name == "SystemTextJsonOutputFormatter") ? - AspNetCoreOpenApiDocumentGenerator.GetSystemTextJsonSettings(services) : null; + .Any(f => f.GetType().Name == "SystemTextJsonOutputFormatter") + ? AspNetCoreOpenApiDocumentGenerator.GetSystemTextJsonSettings(services) +#if NET6_0_OR_GREATER + : services.GetService>()?.Value.SerializerOptions; +#else + : null; +#endif if (systemTextJsonOptions != null) {