diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index 9eb55fa..4bf48be 100755 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -3,10 +3,10 @@ id: f1a8c321-72a7-41c5-8f5e-3d925aeafa1a management: docChecksum: 2401c7030f847f72ab31c8f75de58a66 docVersion: 0.2.0 - speakeasyVersion: 1.213.0 - generationVersion: 2.283.1 - releaseVersion: 0.1.0 - configChecksum: ef8305e66f6c0da55e15a2c60e06f357 + speakeasyVersion: 1.227.0 + generationVersion: 2.291.0 + releaseVersion: 0.1.1 + configChecksum: cf7f772784da84b4987084bd63356eed repoURL: https://github.com/StyraInc/opa-csharp.git features: csharp: @@ -14,13 +14,14 @@ features: examples: 2.81.3 flattening: 2.81.1 globalServerURLs: 2.82.3 - unions: 0.0.1 + unions: 0.0.2 generatedFiles: - Api/Opa.cs - global.json - - Api/Utils/BigIntSerializer.cs - - Api/Utils/DecimalSerializer.cs - - Api/Utils/EnumSerializer.cs + - Api/Utils/AnyDeserializer.cs + - Api/Utils/BigIntStrConverter.cs + - Api/Utils/DecimalStrConverter.cs + - Api/Utils/EnumConverter.cs - Api/Utils/FlexibleObjectDeserializer.cs - Api/Utils/HeaderSerializer.cs - Api/Utils/IsoDateTimeSerializer.cs diff --git a/.speakeasy/gen.yaml b/.speakeasy/gen.yaml index 5034afb..ecdb11c 100755 --- a/.speakeasy/gen.yaml +++ b/.speakeasy/gen.yaml @@ -12,7 +12,7 @@ generation: auth: oAuth2ClientCredentialsEnabled: false csharp: - version: 0.1.0 + version: 0.1.1 author: Styra dotnetVersion: net6.0 flattenGlobalSecurity: true diff --git a/Api/Api.csproj b/Api/Api.csproj index 91a1f87..698292d 100644 --- a/Api/Api.csproj +++ b/Api/Api.csproj @@ -2,7 +2,7 @@ true api - 0.1.0 + 0.1.1 Styra net6.0 enable diff --git a/Api/Models/Components/Input.cs b/Api/Models/Components/Input.cs index b2b9a51..7a2ca37 100644 --- a/Api/Models/Components/Input.cs +++ b/Api/Models/Components/Input.cs @@ -33,7 +33,7 @@ public class InputType public static InputType Number { get { return new InputType("number"); } } - public static InputType Null { get { return new InputType("null"); } } + public static InputType Null { get { return new InputType("null"); } } public override string ToString() { return Value; } public static implicit operator String(InputType v) { return v.Value; } @@ -77,7 +77,7 @@ public Input(InputType type) { public List? ArrayOfany { get; set; } public double? Number { get; set; } - public InputType Type {get; set; } + public InputType Type { get; set; } public static Input CreateMapOfany(Dictionary mapOfany) { @@ -141,7 +141,7 @@ public class InputConverter : JsonConverter } try { - Dictionary? mapOfany = JsonConvert.DeserializeObject>(json, new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Error, Converters = Utilities.GetJsonConverters(typeof(Dictionary), "string")}); + Dictionary? mapOfany = JsonConvert.DeserializeObject>(json, new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Error, Converters = Utilities.GetJsonConverters(typeof(Dictionary))}); return new Input(InputType.MapOfany) { MapOfany = mapOfany }; @@ -167,7 +167,7 @@ public class InputConverter : JsonConverter } try { - List? arrayOfany = JsonConvert.DeserializeObject>(json, new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Error, Converters = Utilities.GetJsonConverters(typeof(List), "string")}); + List? arrayOfany = JsonConvert.DeserializeObject>(json, new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Error, Converters = Utilities.GetJsonConverters(typeof(List))}); return new Input(InputType.ArrayOfany) { ArrayOfany = arrayOfany }; @@ -233,5 +233,4 @@ public override void WriteJson(JsonWriter writer, object? value, JsonSerializer } - } \ No newline at end of file diff --git a/Api/Models/Components/Result.cs b/Api/Models/Components/Result.cs index 717c724..6d5fefb 100644 --- a/Api/Models/Components/Result.cs +++ b/Api/Models/Components/Result.cs @@ -33,7 +33,7 @@ public class ResultType public static ResultType Number { get { return new ResultType("number"); } } - public static ResultType Null { get { return new ResultType("null"); } } + public static ResultType Null { get { return new ResultType("null"); } } public override string ToString() { return Value; } public static implicit operator String(ResultType v) { return v.Value; } @@ -77,7 +77,7 @@ public Result(ResultType type) { public List? ArrayOfany { get; set; } public double? Number { get; set; } - public ResultType Type {get; set; } + public ResultType Type { get; set; } public static Result CreateMapOfany(Dictionary mapOfany) { @@ -141,7 +141,7 @@ public class ResultConverter : JsonConverter } try { - Dictionary? mapOfany = JsonConvert.DeserializeObject>(json, new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Error, Converters = Utilities.GetJsonConverters(typeof(Dictionary), "string")}); + Dictionary? mapOfany = JsonConvert.DeserializeObject>(json, new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Error, Converters = Utilities.GetJsonConverters(typeof(Dictionary))}); return new Result(ResultType.MapOfany) { MapOfany = mapOfany }; @@ -167,7 +167,7 @@ public class ResultConverter : JsonConverter } try { - List? arrayOfany = JsonConvert.DeserializeObject>(json, new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Error, Converters = Utilities.GetJsonConverters(typeof(List), "string")}); + List? arrayOfany = JsonConvert.DeserializeObject>(json, new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Error, Converters = Utilities.GetJsonConverters(typeof(List))}); return new Result(ResultType.ArrayOfany) { ArrayOfany = arrayOfany }; @@ -233,5 +233,4 @@ public override void WriteJson(JsonWriter writer, object? value, JsonSerializer } - } \ No newline at end of file diff --git a/Api/Opa.cs b/Api/Opa.cs index d510e74..0878164 100644 --- a/Api/Opa.cs +++ b/Api/Opa.cs @@ -78,10 +78,10 @@ public class Opa: IOpa public SDKConfig SDKConfiguration { get; private set; } private const string _language = "csharp"; - private const string _sdkVersion = "0.1.0"; - private const string _sdkGenVersion = "2.283.1"; + private const string _sdkVersion = "0.1.1"; + private const string _sdkGenVersion = "2.291.0"; private const string _openapiDocVersion = "0.2.0"; - private const string _userAgent = "speakeasy-sdk/csharp 0.1.0 2.283.1 0.2.0 api"; + private const string _userAgent = "speakeasy-sdk/csharp 0.1.1 2.291.0 0.2.0 api"; private string _serverUrl = ""; private int _serverIndex = 0; private ISpeakeasyHttpClient _defaultClient; @@ -142,7 +142,7 @@ public async Task ExecutePolicyAsync(ExecutePolicyRequest { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { - response.SuccessfulPolicyEvaluation = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); + response.SuccessfulPolicyEvaluation = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumConverter(), new AnyDeserializer() }}); } return response; @@ -152,7 +152,7 @@ public async Task ExecutePolicyAsync(ExecutePolicyRequest { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { - response.ClientError = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); + response.ClientError = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumConverter(), new AnyDeserializer() }}); } return response; @@ -162,7 +162,7 @@ public async Task ExecutePolicyAsync(ExecutePolicyRequest { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { - response.ServerError = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); + response.ServerError = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumConverter(), new AnyDeserializer() }}); } return response; @@ -203,7 +203,7 @@ public async Task ExecutePolicyWithInputAsync(Ex { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { - response.SuccessfulPolicyEvaluation = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); + response.SuccessfulPolicyEvaluation = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumConverter(), new AnyDeserializer() }}); } return response; @@ -213,7 +213,7 @@ public async Task ExecutePolicyWithInputAsync(Ex { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { - response.ClientError = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); + response.ClientError = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumConverter(), new AnyDeserializer() }}); } return response; @@ -223,7 +223,7 @@ public async Task ExecutePolicyWithInputAsync(Ex { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { - response.ServerError = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); + response.ServerError = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumConverter(), new AnyDeserializer() }}); } return response; @@ -263,7 +263,7 @@ public async Task HealthAsync(bool? bundles = null, bool? plugin { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { - response.HealthyServer = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); + response.HealthyServer = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumConverter(), new AnyDeserializer() }}); } return response; @@ -273,7 +273,7 @@ public async Task HealthAsync(bool? bundles = null, bool? plugin { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { - response.UnhealthyServer = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); + response.UnhealthyServer = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumConverter(), new AnyDeserializer() }}); } return response; diff --git a/Api/Utils/AnyDeserializer.cs b/Api/Utils/AnyDeserializer.cs new file mode 100644 index 0000000..c369f08 --- /dev/null +++ b/Api/Utils/AnyDeserializer.cs @@ -0,0 +1,92 @@ + +//------------------------------------------------------------------------------ +// +// This code was generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// +// Changes to this file may cause incorrect behavior and will be lost when +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable +namespace Api.Utils +{ + using Newtonsoft.Json; + using Newtonsoft.Json.Linq; + using System; + using System.Collections.Generic; + + public class AnyDeserializer : JsonConverter + { + public override bool CanConvert(Type objectType) + { + return (objectType == typeof(Dictionary)); + } + + public override bool CanWrite => false; + + public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) + { + throw new NotSupportedException(); + } + + public override object ReadJson( + JsonReader reader, + Type objectType, + object? existingValue, + JsonSerializer serializer + ) + { + return ParseTokenIntoDictionary(JToken.Load(reader)); + } + + private Dictionary ParseTokenIntoDictionary(JToken token) + { + var dict = new Dictionary(); + + foreach (var child in token.Children()) + { + + object? val = null; + if (child.Value is JObject) + { + val = ParseTokenIntoDictionary(child.Value); + } + else if (child.Value is JArray) + { + val = ParseTokenIntoList(child.Value); + } + else if (child.Value != null) + { + val = ((JValue)child.Value).Value; + } + + dict[child.Name] = val; + } + + return dict; + } + + private List ParseTokenIntoList(JToken token) + { + var list = new List(); + + foreach (var child in token.Children()) + { + if (child is JObject) + { + list.Add((object)ParseTokenIntoDictionary(child)); + } + else if (child is JArray) + { + list.Add((object)ParseTokenIntoList(child)); + } + else + { + list.Add(((JValue)child).Value); + } + } + + return list; + } + } +} \ No newline at end of file diff --git a/Api/Utils/BigIntSerializer.cs b/Api/Utils/BigIntStrConverter.cs similarity index 90% rename from Api/Utils/BigIntSerializer.cs rename to Api/Utils/BigIntStrConverter.cs index 2def2c6..8519266 100644 --- a/Api/Utils/BigIntSerializer.cs +++ b/Api/Utils/BigIntStrConverter.cs @@ -14,12 +14,13 @@ namespace Api.Utils using System.Globalization; using System.Numerics; using Newtonsoft.Json; + using Newtonsoft.Json.Linq; - internal class BigIntSerializer : JsonConverter + internal class BigIntStrConverter : JsonConverter { public override bool CanConvert(Type objectType) { - var nullableType = Nullable.GetUnderlyingType(objectType); + var nullableType = Nullable.GetUnderlyingType(objectType); if (nullableType != null) { return nullableType == typeof(BigInteger); @@ -28,8 +29,6 @@ public override bool CanConvert(Type objectType) return objectType == typeof(BigInteger); } - public override bool CanRead => true; - public override object? ReadJson( JsonReader reader, Type objectType, diff --git a/Api/Utils/DecimalSerializer.cs b/Api/Utils/DecimalStrConverter.cs similarity index 81% rename from Api/Utils/DecimalSerializer.cs rename to Api/Utils/DecimalStrConverter.cs index 28620f3..cca1266 100644 --- a/Api/Utils/DecimalSerializer.cs +++ b/Api/Utils/DecimalStrConverter.cs @@ -13,8 +13,9 @@ namespace Api.Utils using System; using System.Globalization; using Newtonsoft.Json; + using Newtonsoft.Json.Linq; - internal class DecimalSerializer : JsonConverter + internal class DecimalStrConverter : JsonConverter { public override bool CanConvert(Type objectType) { @@ -27,8 +28,6 @@ public override bool CanConvert(Type objectType) return objectType == typeof(Decimal); } - public override bool CanRead => true; - public override object? ReadJson( JsonReader reader, Type objectType, @@ -41,7 +40,11 @@ JsonSerializer serializer return null; } - return Decimal.Parse(reader.Value.ToString()!); + try { + return Decimal.Parse(reader.Value.ToString()!); + } catch (System.FormatException ex) { + throw new Newtonsoft.Json.JsonSerializationException("Could not parse Decimal", ex); + } } public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) diff --git a/Api/Utils/EnumSerializer.cs b/Api/Utils/EnumConverter.cs similarity index 96% rename from Api/Utils/EnumSerializer.cs rename to Api/Utils/EnumConverter.cs index 5dbc138..f0ba744 100644 --- a/Api/Utils/EnumSerializer.cs +++ b/Api/Utils/EnumConverter.cs @@ -13,7 +13,7 @@ namespace Api.Utils { - internal class EnumSerializer : JsonConverter + internal class EnumConverter : JsonConverter { public override bool CanConvert(System.Type objectType) { @@ -26,8 +26,6 @@ public override bool CanConvert(System.Type objectType) return objectType.IsEnum; } - public override bool CanRead => true; - public override object? ReadJson( JsonReader reader, System.Type objectType, diff --git a/Api/Utils/Utilities.cs b/Api/Utils/Utilities.cs index 86273c8..4bb9595 100644 --- a/Api/Utils/Utilities.cs +++ b/Api/Utils/Utilities.cs @@ -22,26 +22,40 @@ namespace Api.Utils public class Utilities { + public static JsonConverter[] GetDefaultJsonConverters() + { + return new JsonConverter[] + { + new IsoDateTimeSerializer(), + new EnumConverter() + }; + } + + public static JsonSerializerSettings GetDefaultJsonSerializerSettings() + { + return new JsonSerializerSettings() + { + NullValueHandling = NullValueHandling.Ignore, + Converters = GetDefaultJsonConverters() + }; + } + public static JsonConverter[] GetJsonConverters(Type type, string format = "") { if (format == "string") { if (type == typeof(BigInteger)) { - return new JsonConverter[] { new BigIntSerializer() }; + return new JsonConverter[] { new BigIntStrConverter() }; } + if (type == typeof(Decimal)) { - return new JsonConverter[] { new DecimalSerializer() }; + return new JsonConverter[] { new DecimalStrConverter() }; } } - return new JsonConverter[] - { - new IsoDateTimeSerializer(), - new EnumSerializer(), - new FlexibleObjectDeserializer() - }; + return GetDefaultJsonConverters(); } public static string SerializeJSON(object obj, string format = "") @@ -201,9 +215,12 @@ public static string ToString(object? obj) if (IsDate(obj)) { - return StripSurroundingQuotes(JsonConvert.SerializeObject(obj, new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new IsoDateTimeSerializer(), new EnumSerializer() }})); + return StripSurroundingQuotes( + JsonConvert.SerializeObject(obj, GetDefaultJsonSerializerSettings()) + ); } - return JsonConvert.SerializeObject(obj, new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new IsoDateTimeSerializer(), new EnumSerializer() }}); + + return JsonConvert.SerializeObject(obj, GetDefaultJsonSerializerSettings()); } public static bool IsContentTypeMatch(string expected, string? actual) diff --git a/RELEASES.md b/RELEASES.md index 7aa5b53..9527c9a 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -30,4 +30,12 @@ Based on: - OpenAPI Doc - Speakeasy CLI 1.213.0 (2.283.1) https://github.com/speakeasy-api/speakeasy ### Generated -- [csharp v0.1.0] . \ No newline at end of file +- [csharp v0.1.0] . + +## 2024-03-27 00:03:10 +### Changes +Based on: +- OpenAPI Doc +- Speakeasy CLI 1.227.0 (2.291.0) https://github.com/speakeasy-api/speakeasy +### Generated +- [csharp v0.1.1] . \ No newline at end of file