-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added Trimming support for CLI generated code.
- Loading branch information
Showing
11 changed files
with
3,004 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/libs/OpenApiGenerator.Core/Generation/Sources.JsonSerializerContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using OpenApiGenerator.Core.Extensions; | ||
using OpenApiGenerator.Core.Json; | ||
using OpenApiGenerator.Core.Models; | ||
|
||
namespace OpenApiGenerator.Core.Generation; | ||
|
||
public static partial class Sources | ||
{ | ||
public static string GenerateJsonSerializerContext( | ||
EndPoint endPoint, | ||
EquatableArray<TypeData> types, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
if (!endPoint.Settings.FromCli || | ||
!endPoint.Settings.GenerateJsonSerializerContextTypes || | ||
endPoint.Settings.JsonSerializerType != JsonSerializerType.SystemTextJson) | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
return $@" | ||
#nullable enable | ||
#pragma warning disable CS0618 // Type or member is obsolete | ||
namespace {endPoint.Namespace} | ||
{{ | ||
[global::System.Text.Json.Serialization.JsonSourceGenerationOptions( | ||
DefaultIgnoreCondition = global::System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull, | ||
Converters = new global::System.Type[] | ||
{{ | ||
{endPoint.Converters.Select(x => $@" | ||
typeof({x}), | ||
").Inject()} | ||
}})] | ||
[global::System.Text.Json.Serialization.JsonSerializable(typeof(global::{endPoint.Namespace}.JsonSerializerContextTypes))] | ||
internal sealed partial class SourceGenerationContext : global::System.Text.Json.Serialization.JsonSerializerContext | ||
{{ | ||
}} | ||
}}".RemoveBlankLinesWhereOnlyWhitespaces(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.