diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index 6c37756..5798b0d 100755 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -3,17 +3,17 @@ id: 76b4d38c-5441-40d8-8002-c456a3ea1652 management: docChecksum: 85248a8dd6a5cd6fea1b82dfc30249e9 docVersion: 1.0.0 - speakeasyVersion: 1.313.0 - generationVersion: 2.347.8 - releaseVersion: 0.17.4 - configChecksum: 35c6c096998276954844755a4be5a0e5 + speakeasyVersion: 1.314.2 + generationVersion: 2.349.6 + releaseVersion: 0.17.5 + configChecksum: bd4b62f4ad23e5fa766cbf429aabbe01 repoURL: https://github.com/ding-live/ding-csharp.git repoSubDirectory: . published: true features: csharp: additionalDependencies: 0.1.0 - core: 3.9.7 + core: 3.9.8 examples: 2.81.3 flattening: 2.81.2 globalSecurity: 2.83.4 diff --git a/DingSDK/Ding.cs b/DingSDK/Ding.cs index 86cbee4..0d5e262 100644 --- a/DingSDK/Ding.cs +++ b/DingSDK/Ding.cs @@ -80,10 +80,10 @@ public class Ding: IDing public SDKConfig SDKConfiguration { get; private set; } private const string _language = "csharp"; - private const string _sdkVersion = "0.17.4"; - private const string _sdkGenVersion = "2.347.8"; + private const string _sdkVersion = "0.17.5"; + private const string _sdkGenVersion = "2.349.6"; private const string _openapiDocVersion = "1.0.0"; - private const string _userAgent = "speakeasy-sdk/csharp 0.17.4 2.347.8 1.0.0 DingSDK"; + private const string _userAgent = "speakeasy-sdk/csharp 0.17.5 2.349.6 1.0.0 DingSDK"; private string _serverUrl = ""; private int _serverIndex = 0; private ISpeakeasyHttpClient _client; diff --git a/DingSDK/DingSDK.csproj b/DingSDK/DingSDK.csproj index 233d433..38362d6 100644 --- a/DingSDK/DingSDK.csproj +++ b/DingSDK/DingSDK.csproj @@ -2,20 +2,20 @@ true DingSDK - 0.17.4 + 0.17.5 Ding net5.0 enable README.md - LICENSE.txt + LICENSE.md true 1591 https://github.com/ding-live/ding-csharp - - + + diff --git a/DingSDK/Lookup.cs b/DingSDK/Lookup.cs index 0892dc6..89f9ddf 100644 --- a/DingSDK/Lookup.cs +++ b/DingSDK/Lookup.cs @@ -41,10 +41,10 @@ public class Lookup: ILookup { public SDKConfig SDKConfiguration { get; private set; } private const string _language = "csharp"; - private const string _sdkVersion = "0.17.4"; - private const string _sdkGenVersion = "2.347.8"; + private const string _sdkVersion = "0.17.5"; + private const string _sdkGenVersion = "2.349.6"; private const string _openapiDocVersion = "1.0.0"; - private const string _userAgent = "speakeasy-sdk/csharp 0.17.4 2.347.8 1.0.0 DingSDK"; + private const string _userAgent = "speakeasy-sdk/csharp 0.17.5 2.349.6 1.0.0 DingSDK"; private string _serverUrl = ""; private ISpeakeasyHttpClient _client; private Func? _securitySource; diff --git a/DingSDK/Otp.cs b/DingSDK/Otp.cs index 3b72c1e..bb39dfe 100644 --- a/DingSDK/Otp.cs +++ b/DingSDK/Otp.cs @@ -56,10 +56,10 @@ public class Otp: IOtp { public SDKConfig SDKConfiguration { get; private set; } private const string _language = "csharp"; - private const string _sdkVersion = "0.17.4"; - private const string _sdkGenVersion = "2.347.8"; + private const string _sdkVersion = "0.17.5"; + private const string _sdkGenVersion = "2.349.6"; private const string _openapiDocVersion = "1.0.0"; - private const string _userAgent = "speakeasy-sdk/csharp 0.17.4 2.347.8 1.0.0 DingSDK"; + private const string _userAgent = "speakeasy-sdk/csharp 0.17.5 2.349.6 1.0.0 DingSDK"; private string _serverUrl = ""; private ISpeakeasyHttpClient _client; private Func? _securitySource; diff --git a/DingSDK/Utils/ResponseBodyDeserializer.cs b/DingSDK/Utils/ResponseBodyDeserializer.cs index ba88e9f..b57c6d2 100644 --- a/DingSDK/Utils/ResponseBodyDeserializer.cs +++ b/DingSDK/Utils/ResponseBodyDeserializer.cs @@ -12,10 +12,12 @@ namespace DingSDK.Utils using System; using System.Collections; using System.Collections.Generic; + using System.Linq; using System.Net.Http; using System.Reflection; using System.Text; using Newtonsoft.Json; + using Newtonsoft.Json.Linq; internal class ResponseBodyDeserializer @@ -25,5 +27,96 @@ internal class ResponseBodyDeserializer { return JsonConvert.DeserializeObject(json, new JsonSerializerSettings(){ NullValueHandling = nullValueHandling, MissingMemberHandling = missingMemberHandling, Converters = Utilities.GetJsonDeserializers(typeof(T))}); } + + public sealed class MissingMemberException : Exception + { + public MissingMemberException() : base("Missing member.") { } + } + + public sealed class DeserializationException : Exception + { + public DeserializationException(Type type) : base($"Could not deserialize into {type} type.") { } + } + + public static T? DeserializeUndiscriminatedUnionMember(string json) + { + try + { + return Deserialize(json, missingMemberHandling: MissingMemberHandling.Error); + } + catch (Exception ex) + { + if (ex is Newtonsoft.Json.JsonSerializationException && + ex.Source == "Newtonsoft.Json" && + ex.Message.Contains("Could not find member")) + { + throw new MissingMemberException(); + } + else if (ex is Newtonsoft.Json.JsonReaderException || + ex is Newtonsoft.Json.JsonSerializationException + ) + { + throw new DeserializationException(typeof(T)); + } + + throw; + } + } + + public static object DeserializeUndiscriminatedUnionFallback(System.Type type, object obj, string propertyName, string json) + { + MethodInfo? method = typeof(ResponseBodyDeserializer).GetMethod("Deserialize"); + if (method != null) + { + MethodInfo generic = method!.MakeGenericMethod(type); + var args = new object[] { json, NullValueHandling.Ignore, MissingMemberHandling.Ignore }; + var value = generic.Invoke(null, args); + PropertyInfo? propertyInfo = obj.GetType().GetProperty(propertyName!); + if (propertyInfo != null && value != null) + { + propertyInfo!.SetValue(obj, value!); + return obj; + } + } + + throw new DeserializationException(type); + } + + public static int MissingJsonProperties(System.Type type, string json) + { + int missing = 0; + + JObject jo = JObject.Parse(json); + + var jsonPropertyAttributes = type.GetProperties() + .Where(prop => Attribute.IsDefined(prop, typeof(JsonPropertyAttribute))) + .Select(prop => prop.GetCustomAttribute(typeof(JsonPropertyAttribute)) as JsonPropertyAttribute) + .Where(attr => attr != null && attr!.PropertyName != null) + .ToList(); + + foreach (var attr in jsonPropertyAttributes) + { + string propertyName = attr!.PropertyName!; + if (!jo.TryGetValue(propertyName, out var _value)){ + missing++; + } + } + + return missing; + } + + public static int CompareFallbackCandidates(System.Type typeA, System.Type typeB, string json) + { + var missingA = MissingJsonProperties(typeA, json); + var missingB = MissingJsonProperties(typeB, json); + + if (missingA == missingB) + { + return typeB.GetProperties().Count().CompareTo(typeA.GetProperties().Count()); + } + + return missingA.CompareTo(missingB); + } + } } \ No newline at end of file diff --git a/NUGET.md b/NUGET.md index b1c78ed..ced7d0c 100644 --- a/NUGET.md +++ b/NUGET.md @@ -1,20 +1,5 @@ # DingSDK -
- - - - -
- - - -## Installation - -```bash -dotnet add package DingSDK -``` - ## SDK Example Usage @@ -90,14 +75,6 @@ var res = await sdk.Otp.RetryAsync(req); ``` - -## Available Resources and Operations - -- [Ding SDK](https:/github.com/ding-live/ding-csharp/blob/main/github/workspace/repo/docs/sdks/ding/README.md#available-operations) -- [Otp](https:/github.com/ding-live/ding-csharp/blob/main/github/workspace/repo/docs/sdks/otp/README.md#available-operations) -- [Lookup](https:/github.com/ding-live/ding-csharp/blob/main/github/workspace/repo/docs/sdks/lookup/README.md#available-operations) - - ## Error Handling diff --git a/RELEASES.md b/RELEASES.md index b525207..b0e0b07 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -380,4 +380,14 @@ Based on: ### Generated - [csharp v0.17.4] . ### Releases -- [NuGet v0.17.4] https://www.nuget.org/packages/DingSDK/0.17.4 - . \ No newline at end of file +- [NuGet v0.17.4] https://www.nuget.org/packages/DingSDK/0.17.4 - . + +## 2024-06-22 00:17:30 +### Changes +Based on: +- OpenAPI Doc 1.0.0 +- Speakeasy CLI 1.314.2 (2.349.6) https://github.com/speakeasy-api/speakeasy +### Generated +- [csharp v0.17.5] . +### Releases +- [NuGet v0.17.5] https://www.nuget.org/packages/DingSDK/0.17.5 - . \ No newline at end of file diff --git a/gen.yaml b/gen.yaml index 51f186f..98eccad 100644 --- a/gen.yaml +++ b/gen.yaml @@ -10,7 +10,7 @@ generation: auth: oAuth2ClientCredentialsEnabled: false csharp: - version: 0.17.4 + version: 0.17.5 additionalDependencies: [] author: Ding clientServerStatusCodesAsErrors: true