From 68d0125a777fa36788e38a80053ada6e7ae84cb6 Mon Sep 17 00:00:00 2001 From: Bonuspunkt Date: Thu, 14 Mar 2024 22:29:19 +0100 Subject: [PATCH] add support for `Microsoft.AspNetCore.Http.Json.JsonOptions` (#4733) --- .../Extensions/NSwagServiceCollectionExtensions.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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) {