-
-
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 ability to use Newtonsoft.Json.
- Loading branch information
Showing
41 changed files
with
268 additions
and
226 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace OpenApiGenerator.Core.Json; | ||
|
||
public interface IJsonSerializer | ||
{ | ||
public string GeneratePropertyAttribute(string id); | ||
string GenerateExtensionDataAttribute(); | ||
} |
15 changes: 15 additions & 0 deletions
15
src/libs/OpenApiGenerator.Core/Json/JsonSerializationTypeExtensions.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,15 @@ | ||
namespace OpenApiGenerator.Core.Json; | ||
|
||
public static class JsonSerializationTypeExtensions | ||
{ | ||
// Returns the serializer type based on the provided enum value. | ||
public static IJsonSerializer GetSerializer(this JsonSerializerType type) | ||
{ | ||
return type switch | ||
{ | ||
JsonSerializerType.SystemTextJson => SystemTextJsonSerializer.Instance, | ||
JsonSerializerType.NewtonsoftJson => NewtonsoftJsonSerializer.Instance, | ||
_ => throw new NotSupportedException($"Serializer type {type} is not supported.") | ||
}; | ||
} | ||
} |
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,7 @@ | ||
namespace OpenApiGenerator.Core.Json; | ||
|
||
public enum JsonSerializerType | ||
{ | ||
SystemTextJson, | ||
NewtonsoftJson, | ||
} |
16 changes: 16 additions & 0 deletions
16
src/libs/OpenApiGenerator.Core/Json/NewtonsoftJsonSerializer.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,16 @@ | ||
namespace OpenApiGenerator.Core.Json; | ||
|
||
public class NewtonsoftJsonSerializer : IJsonSerializer | ||
{ | ||
public static IJsonSerializer Instance { get; } = new NewtonsoftJsonSerializer(); | ||
|
||
public string GeneratePropertyAttribute(string id) | ||
{ | ||
return $"[global::Newtonsoft.Json.JsonProperty(\"{id}\")]"; | ||
} | ||
|
||
public string GenerateExtensionDataAttribute() | ||
{ | ||
return "[global::Newtonsoft.Json.JsonExtensionData]"; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/libs/OpenApiGenerator.Core/Json/SystemTextJsonSerializer.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,16 @@ | ||
namespace OpenApiGenerator.Core.Json; | ||
|
||
public class SystemTextJsonSerializer : IJsonSerializer | ||
{ | ||
public static IJsonSerializer Instance { get; } = new SystemTextJsonSerializer(); | ||
|
||
public string GeneratePropertyAttribute(string id) | ||
{ | ||
return $"[global::System.Text.Json.Serialization.JsonPropertyName(\"{id}\")]"; | ||
} | ||
|
||
public string GenerateExtensionDataAttribute() | ||
{ | ||
return "[global::System.Text.Json.Serialization.JsonExtensionData]"; | ||
} | ||
} |
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
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
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
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.