Skip to content

Commit

Permalink
fix: Fixed JsonSerializerContext array types.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed May 31, 2024
1 parent a9d7d66 commit 58d2f47
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 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.4</Version>
<Version>0.9.5</Version>
<MinVerMinimumMajorMinor>0.1</MinVerMinimumMajorMinor>
<MinVerTagPrefix>v</MinVerTagPrefix>
<MinVerDefaultPreReleaseIdentifiers>dev</MinVerDefaultPreReleaseIdentifiers>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ public string GenerateConverterAttribute(string type)
return $"[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.{type}))]";
}

private static readonly char[] ContextTypeSeparators = [',', '<', '>'];
private static readonly char[] ContextTypeSeparators = [',', '<', '>', '['];

private static string GetContextType(string type)
public static string GetContextType(string type)
{
type = type ?? throw new ArgumentNullException(nameof(type));

return string.Concat(type
.Replace("global::", string.Empty)
.TrimEnd('?')
Expand All @@ -41,6 +43,7 @@ private static string GetContextType(string type)
.Split(ContextTypeSeparators, StringSplitOptions.RemoveEmptyEntries)
.Select(x => x.Trim() switch
{
"]" => "Array",
"bool" => "Boolean",
"short" => "Int16",
"int" => "Int32",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using static OpenApiGenerator.Core.Json.SystemTextJsonSerializer;

namespace OpenApiGenerator.UnitTests;

public partial class JsonTests
{
[TestMethod]
public void ContextTypes()
{
GetContextType("global::System.Collections.Generic.List<string>").Should().Be("ListString");
GetContextType("global::System.Collections.Generic.Dictionary<string, int>").Should().Be("DictionaryStringInt32");
GetContextType("byte[]").Should().Be("ByteArray");
GetContextType("byte[][]").Should().Be("ByteArrayArray");
GetContextType("global::System.Collections.Generic.List<byte[]>").Should().Be("ListByteArray");
GetContextType("global::System.Collections.Generic.List<byte[][]>").Should().Be("ListByteArrayArray");
}
}

0 comments on commit 58d2f47

Please sign in to comment.