Skip to content

Commit

Permalink
feat: Added JsonSerializerContextConverters generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Jun 5, 2024
1 parent fae8c1f commit 67ef471
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/libs/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</ItemGroup>

<PropertyGroup Label="Versioning">
<Version>0.9.9</Version>
<Version>0.9.10</Version>
<MinVerMinimumMajorMinor>0.1</MinVerMinimumMajorMinor>
<MinVerTagPrefix>v</MinVerTagPrefix>
<MinVerDefaultPreReleaseIdentifiers>dev</MinVerDefaultPreReleaseIdentifiers>
Expand Down
14 changes: 13 additions & 1 deletion src/libs/OpenApiGenerator.Core/Generation/Sources.Clients.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 67ef471

Please sign in to comment.