Skip to content

Commit

Permalink
Release v0.3.38
Browse files Browse the repository at this point in the history
  • Loading branch information
fern-api[bot] committed Jun 3, 2024
1 parent 6f3d17d commit 4746661
Show file tree
Hide file tree
Showing 224 changed files with 956 additions and 275 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 7.0.404
dotnet-version: 8.x

- name: Install tools
run: |
Expand All @@ -37,7 +37,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 7.0.404
dotnet-version: 8.x

- name: Publish
env:
Expand Down
20 changes: 10 additions & 10 deletions src/Mercoa.Client.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mercoa.Client", "Mercoa.Client\Mercoa.Client.csproj", "{4E9723B5-0D4E-4C47-876C-2496478B955E}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mercoa.Client", "Mercoa.Client\Mercoa.Client.csproj", "{EC873A1C-C5D6-4DA8-A16E-72350EFA4E82}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mercoa.Client.Test", "Mercoa.Client.Test\Mercoa.Client.Test.csproj", "{730ABA81-798E-4B9B-91C2-F4956628D257}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mercoa.Client.Test", "Mercoa.Client.Test\Mercoa.Client.Test.csproj", "{57C6771A-DF68-48BA-B583-99AA311726B1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -16,13 +16,13 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4E9723B5-0D4E-4C47-876C-2496478B955E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4E9723B5-0D4E-4C47-876C-2496478B955E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4E9723B5-0D4E-4C47-876C-2496478B955E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4E9723B5-0D4E-4C47-876C-2496478B955E}.Release|Any CPU.Build.0 = Release|Any CPU
{730ABA81-798E-4B9B-91C2-F4956628D257}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{730ABA81-798E-4B9B-91C2-F4956628D257}.Debug|Any CPU.Build.0 = Debug|Any CPU
{730ABA81-798E-4B9B-91C2-F4956628D257}.Release|Any CPU.ActiveCfg = Release|Any CPU
{730ABA81-798E-4B9B-91C2-F4956628D257}.Release|Any CPU.Build.0 = Release|Any CPU
{EC873A1C-C5D6-4DA8-A16E-72350EFA4E82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EC873A1C-C5D6-4DA8-A16E-72350EFA4E82}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EC873A1C-C5D6-4DA8-A16E-72350EFA4E82}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EC873A1C-C5D6-4DA8-A16E-72350EFA4E82}.Release|Any CPU.Build.0 = Release|Any CPU
{57C6771A-DF68-48BA-B583-99AA311726B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{57C6771A-DF68-48BA-B583-99AA311726B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{57C6771A-DF68-48BA-B583-99AA311726B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{57C6771A-DF68-48BA-B583-99AA311726B1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
4 changes: 3 additions & 1 deletion src/Mercoa.Client/BankLookup/BankLookupClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Text.Json;
using Mercoa.Client;

#nullable enable

namespace Mercoa.Client;

public class BankLookupClient
Expand Down Expand Up @@ -34,6 +36,6 @@ public async Task<BankLookupResponse> FindAsync(BankLookupRequest request)
{
return JsonSerializer.Deserialize<BankLookupResponse>(responseBody);
}
throw new Exception();
throw new Exception(responseBody);
}
}
2 changes: 2 additions & 0 deletions src/Mercoa.Client/BankLookup/Types/BankAddress.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Text.Json.Serialization;

#nullable enable

namespace Mercoa.Client;

public class BankAddress
Expand Down
2 changes: 2 additions & 0 deletions src/Mercoa.Client/BankLookup/Types/BankLookupResponse.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Text.Json.Serialization;
using Mercoa.Client;

#nullable enable

namespace Mercoa.Client;

public class BankLookupResponse
Expand Down
2 changes: 2 additions & 0 deletions src/Mercoa.Client/Commons/CommonsClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Mercoa.Client;

#nullable enable

namespace Mercoa.Client;

public class CommonsClient
Expand Down
2 changes: 2 additions & 0 deletions src/Mercoa.Client/Commons/Types/Address.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Text.Json.Serialization;

#nullable enable

namespace Mercoa.Client;

public class Address
Expand Down
2 changes: 2 additions & 0 deletions src/Mercoa.Client/Commons/Types/BirthDate.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Text.Json.Serialization;

#nullable enable

namespace Mercoa.Client;

public class BirthDate
Expand Down
2 changes: 2 additions & 0 deletions src/Mercoa.Client/Commons/Types/FullName.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Text.Json.Serialization;

#nullable enable

namespace Mercoa.Client;

public class FullName
Expand Down
2 changes: 2 additions & 0 deletions src/Mercoa.Client/Commons/Types/IndividualGovernmentId.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Text.Json.Serialization;

#nullable enable

namespace Mercoa.Client;

public class IndividualGovernmentId
Expand Down
6 changes: 6 additions & 0 deletions src/Mercoa.Client/Commons/Types/OrderDirection.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
using System.Runtime.Serialization;
using System.Text.Json.Serialization;
using Mercoa.Client;
using Mercoa.Client.Core;

#nullable enable

namespace Mercoa.Client;

[JsonConverter(typeof(StringEnumSerializer<OrderDirection>))]
public enum OrderDirection
{
[EnumMember(Value = "ASC")]
Expand Down
2 changes: 2 additions & 0 deletions src/Mercoa.Client/Commons/Types/PhoneNumber.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Text.Json.Serialization;

#nullable enable

namespace Mercoa.Client;

public class PhoneNumber
Expand Down
2 changes: 2 additions & 0 deletions src/Mercoa.Client/Core/ClientOptions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Mercoa.Client.Core;

#nullable enable

namespace Mercoa.Client;

public partial class ClientOptions
Expand Down
92 changes: 92 additions & 0 deletions src/Mercoa.Client/Core/CollectionItemSerializer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Mercoa.Client;

/// <summary>
/// Json collection converter.
/// </summary>
/// <typeparam name="TDatatype">Type of item to convert.</typeparam>
/// <typeparam name="TConverterType">Converter to use for individual items.</typeparam>
public class CollectionItemSerializer<TDatatype, TConverterType>
: JsonConverter<IEnumerable<TDatatype>>
where TConverterType : JsonConverter
{
/// <summary>
/// Reads a json string and deserializes it into an object.
/// </summary>
/// <param name="reader">Json reader.</param>
/// <param name="typeToConvert">Type to convert.</param>
/// <param name="options">Serializer options.</param>
/// <returns>Created object.</returns>
public override IEnumerable<TDatatype> Read(
ref Utf8JsonReader reader,
Type typeToConvert,
JsonSerializerOptions options
)
{
if (reader.TokenType == JsonTokenType.Null)
{
return default(IEnumerable<TDatatype>);
}

JsonSerializerOptions jsonSerializerOptions = new JsonSerializerOptions(options);
jsonSerializerOptions.Converters.Clear();
jsonSerializerOptions.Converters.Add(Activator.CreateInstance<TConverterType>());

List<TDatatype> returnValue = new List<TDatatype>();

while (reader.TokenType != JsonTokenType.EndArray)
{
if (reader.TokenType != JsonTokenType.StartArray)
{
returnValue.Add(
(TDatatype)
JsonSerializer.Deserialize(
ref reader,
typeof(TDatatype),
jsonSerializerOptions
)
);
}

reader.Read();
}

return returnValue;
}

/// <summary>
/// Writes a json string.
/// </summary>
/// <param name="writer">Json writer.</param>
/// <param name="value">Value to write.</param>
/// <param name="options">Serializer options.</param>
public override void Write(
Utf8JsonWriter writer,
IEnumerable<TDatatype> value,
JsonSerializerOptions options
)
{
if (value == null)
{
writer.WriteNullValue();
return;
}

JsonSerializerOptions jsonSerializerOptions = new JsonSerializerOptions(options);
jsonSerializerOptions.Converters.Clear();
jsonSerializerOptions.Converters.Add(Activator.CreateInstance<TConverterType>());

writer.WriteStartArray();

foreach (TDatatype data in value)
{
JsonSerializer.Serialize(writer, data, jsonSerializerOptions);
}

writer.WriteEndArray();
}
}
75 changes: 0 additions & 75 deletions src/Mercoa.Client/Core/JsonEnumMemberStringEnumConverter.cs

This file was deleted.

67 changes: 67 additions & 0 deletions src/Mercoa.Client/Core/OneOfSerializer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Serialization;
using OneOf;

namespace Mercoa.Client;

public class OneOfSerializer<TOneOf> : JsonConverter<TOneOf>
where TOneOf : IOneOf
{
public override TOneOf Read(
ref Utf8JsonReader reader,
Type typeToConvert,
JsonSerializerOptions options
)
{
if (reader.TokenType is JsonTokenType.Null)
return default;

foreach (var (type, cast) in s_types)
{
try
{
Utf8JsonReader readerCopy = reader;
var result = JsonSerializer.Deserialize(ref readerCopy, type, options);
reader.Skip();
return (TOneOf)cast.Invoke(null, new[] { result })!;
}
catch (JsonException) { }
}

throw new JsonException(
$"Cannot deserialize into one of the supported types for {typeToConvert}"
);
}

private static readonly (Type type, MethodInfo cast)[] s_types = GetOneOfTypes();

public override void Write(Utf8JsonWriter writer, TOneOf value, JsonSerializerOptions options)
{
JsonSerializer.Serialize(writer, value.Value, options);
}

private static (Type type, MethodInfo cast)[] GetOneOfTypes()
{
var casts = typeof(TOneOf)
.GetRuntimeMethods()
.Where(m => m.IsSpecialName && m.Name == "op_Implicit")
.ToArray();
var type = typeof(TOneOf);
while (type != null)
{
if (
type.IsGenericType
&& (type.Name.StartsWith("OneOf`") || type.Name.StartsWith("OneOfBase`"))
)
{
return type.GetGenericArguments()
.Select(t => (t, casts.First(c => c.GetParameters()[0].ParameterType == t)))
.ToArray();
}

type = type.BaseType;
}
throw new InvalidOperationException($"{typeof(TOneOf)} isn't OneOf or OneOfBase");
}
}
Loading

0 comments on commit 4746661

Please sign in to comment.