From a585cda584a60e6de9fd57ff8cf37d35d91547b2 Mon Sep 17 00:00:00 2001 From: Bonuspunkt <bonuspunkt+github@gmail.com> Date: Wed, 24 Jan 2024 17:05:13 +0100 Subject: [PATCH] add support for `Microsoft.AspNetCore.Http.Json.JsonOptions` --- .../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<IOptions<MvcOptions>>(); 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<IOptions<Microsoft.AspNetCore.Http.Json.JsonOptions>>()?.Value.SerializerOptions; +#else + : null; +#endif if (systemTextJsonOptions != null) {