From 67ef4716a53942ee3a5a73ce4236d7a5ad50a624 Mon Sep 17 00:00:00 2001 From: HavenDV Date: Wed, 5 Jun 2024 19:56:22 +0400 Subject: [PATCH] feat: Added JsonSerializerContextConverters generation. --- src/libs/Directory.Build.props | 2 +- .../Generation/Sources.Clients.cs | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/libs/Directory.Build.props b/src/libs/Directory.Build.props index 52d8cd0fc6..d5f5ed684a 100644 --- a/src/libs/Directory.Build.props +++ b/src/libs/Directory.Build.props @@ -39,7 +39,7 @@ - 0.9.9 + 0.9.10 0.1 v dev diff --git a/src/libs/OpenApiGenerator.Core/Generation/Sources.Clients.cs b/src/libs/OpenApiGenerator.Core/Generation/Sources.Clients.cs index 2749043f96..3b091614f3 100644 --- a/src/libs/OpenApiGenerator.Core/Generation/Sources.Clients.cs +++ b/src/libs/OpenApiGenerator.Core/Generation/Sources.Clients.cs @@ -12,7 +12,7 @@ public static string GenerateConstructors( var serializer = endPoint.JsonSerializerType.GetSerializer(); var hasOptions = string.IsNullOrWhiteSpace(endPoint.JsonSerializerContext); - return $@" + var code = $@" #nullable enable namespace {endPoint.Namespace} @@ -55,6 +55,18 @@ public void Dispose() }} }} }}".RemoveBlankLinesWhereOnlyWhitespaces(); + if (!hasOptions && endPoint.Id == "MainConstructor") + { + code = code.TrimEnd('}'); + code += $@" + internal class JsonSerializerContextConverters + {{ + private readonly {serializer.GetOptionsType()} _jsonSerializerOptions = {serializer.CreateDefaultSettings(endPoint.Converters)}; + }} +}}".RemoveBlankLinesWhereOnlyWhitespaces(); + } + + return code; } public static string GenerateAuthorizationMethod(