diff --git a/src/libs/OpenApiGenerator.Core/Generation/Sources.JsonConverters.AnyOf.cs b/src/libs/OpenApiGenerator.Core/Generation/Sources.JsonConverters.AnyOf.cs index afa0894070..10dcceeb3f 100644 --- a/src/libs/OpenApiGenerator.Core/Generation/Sources.JsonConverters.AnyOf.cs +++ b/src/libs/OpenApiGenerator.Core/Generation/Sources.JsonConverters.AnyOf.cs @@ -37,7 +37,7 @@ public class {subType}JsonConverter{types} : global::System.Text.Json.Serializat T{x}? value{x} = default; try {{ - value{x} = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value{x} = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); }} catch (global::System.Text.Json.JsonException) {{ @@ -57,7 +57,7 @@ public class {subType}JsonConverter{types} : global::System.Text.Json.Serializat {Enumerable.Range(1, count).Select(x => $@" {(x == 1 ? "" : "else ")}if (value{x} != null) {{ - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); }} ").Inject().TrimEnd(',')} diff --git a/src/libs/OpenApiGenerator.Helpers/JsonConverters/SystemTextJson/AnyOfConverterSystemTextJson.cs b/src/libs/OpenApiGenerator.Helpers/JsonConverters/SystemTextJson/AnyOfConverterSystemTextJson.cs index ba7daeaa96..2eb050b893 100644 --- a/src/libs/OpenApiGenerator.Helpers/JsonConverters/SystemTextJson/AnyOfConverterSystemTextJson.cs +++ b/src/libs/OpenApiGenerator.Helpers/JsonConverters/SystemTextJson/AnyOfConverterSystemTextJson.cs @@ -16,7 +16,7 @@ public override AnyOf Read( T1? value1 = default; try { - value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -26,7 +26,7 @@ public override AnyOf Read( T2? value2 = default; try { - value2 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value2 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -40,11 +40,11 @@ public override AnyOf Read( if (value1 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value2 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } return result; diff --git a/src/libs/OpenApiGenerator.Helpers/JsonEnumConverter/TestEnum.cs b/src/libs/OpenApiGenerator.Helpers/JsonEnumConverter/TestEnum.cs new file mode 100644 index 0000000000..8b10f0f4e2 --- /dev/null +++ b/src/libs/OpenApiGenerator.Helpers/JsonEnumConverter/TestEnum.cs @@ -0,0 +1,7 @@ +namespace OpenApiGenerator.JsonConverters; + +public enum TestEnum +{ + PullingManifest, + Success, +} \ No newline at end of file diff --git a/src/libs/OpenApiGenerator.Helpers/JsonEnumConverter/TestEnumClass.cs b/src/libs/OpenApiGenerator.Helpers/JsonEnumConverter/TestEnumClass.cs new file mode 100644 index 0000000000..a1558286bd --- /dev/null +++ b/src/libs/OpenApiGenerator.Helpers/JsonEnumConverter/TestEnumClass.cs @@ -0,0 +1,8 @@ +namespace OpenApiGenerator.JsonConverters; + +public sealed partial class TestEnumClass +{ + [global::System.Text.Json.Serialization.JsonPropertyName("status")] + [global::System.Text.Json.Serialization.JsonConverter(typeof(TestEnumJsonStringEnumConverter))] + public TestEnum? Status { get; set; } +} \ No newline at end of file diff --git a/src/libs/OpenApiGenerator.Helpers/JsonEnumConverter/TestEnumExtensions.cs b/src/libs/OpenApiGenerator.Helpers/JsonEnumConverter/TestEnumExtensions.cs new file mode 100644 index 0000000000..f726b87ea9 --- /dev/null +++ b/src/libs/OpenApiGenerator.Helpers/JsonEnumConverter/TestEnumExtensions.cs @@ -0,0 +1,26 @@ +using System; + +namespace OpenApiGenerator.JsonConverters; + +public static class TestEnumExtensions +{ + public static string ToValueString(this TestEnum value) + { + return value switch + { + TestEnum.PullingManifest => "pulling manifest", + TestEnum.Success => "success", + _ => throw new ArgumentOutOfRangeException(nameof(value), value, null), + }; + } + + public static TestEnum ToEnum(string value) + { + return value switch + { + "pulling manifest" => TestEnum.PullingManifest, + "success" => TestEnum.Success, + _ => throw new ArgumentOutOfRangeException(nameof(value), value, null), + }; + } +} \ No newline at end of file diff --git a/src/libs/OpenApiGenerator.Helpers/JsonEnumConverter/TestEnumJsonStringEnumConverter.cs b/src/libs/OpenApiGenerator.Helpers/JsonEnumConverter/TestEnumJsonStringEnumConverter.cs new file mode 100644 index 0000000000..c9b4296ccf --- /dev/null +++ b/src/libs/OpenApiGenerator.Helpers/JsonEnumConverter/TestEnumJsonStringEnumConverter.cs @@ -0,0 +1,40 @@ +namespace OpenApiGenerator.JsonConverters; + +public sealed class TestEnumJsonStringEnumConverter : global::System.Text.Json.Serialization.JsonConverter +{ + public override TestEnum Read( + ref global::System.Text.Json.Utf8JsonReader reader, + global::System.Type typeToConvert, + global::System.Text.Json.JsonSerializerOptions options) + { + switch (reader.TokenType) + { + case global::System.Text.Json.JsonTokenType.String: + { + var stringValue = reader.GetString(); + if (stringValue != null) + { + return TestEnumExtensions.ToEnum(stringValue); + } + + break; + } + case global::System.Text.Json.JsonTokenType.Number: + { + return (TestEnum)reader.GetInt32(); + } + default: + throw new global::System.ArgumentOutOfRangeException(); + } + + return default; + } + + public override void Write( + global::System.Text.Json.Utf8JsonWriter writer, + TestEnum value, + global::System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.ToValueString()); + } +} \ No newline at end of file diff --git a/src/libs/OpenApiGenerator.Helpers/JsonEnumConverter/TestEnumNewtonsoftJsonStringEnumConverter.cs b/src/libs/OpenApiGenerator.Helpers/JsonEnumConverter/TestEnumNewtonsoftJsonStringEnumConverter.cs new file mode 100644 index 0000000000..e48fbd09c2 --- /dev/null +++ b/src/libs/OpenApiGenerator.Helpers/JsonEnumConverter/TestEnumNewtonsoftJsonStringEnumConverter.cs @@ -0,0 +1,48 @@ +using System; +using Newtonsoft.Json; + +namespace OpenApiGenerator.JsonConverters; + +public sealed class TestEnumNewtonsoftJsonStringEnumConverter : Newtonsoft.Json.JsonConverter +{ + public override void WriteJson(JsonWriter writer, TestEnum value, Newtonsoft.Json.JsonSerializer serializer) + { + writer.WriteValue(value.ToValueString()); + } + + public override TestEnum ReadJson(JsonReader reader, Type objectType, TestEnum existingValue, bool hasExistingValue, + Newtonsoft.Json.JsonSerializer serializer) + { + if (hasExistingValue) + { + return existingValue; + } + + var type = reader.TokenType; + + switch (type) + { + case JsonToken.String: + { + var stringValue = reader.ReadAsString(); + if (stringValue != null) + { + return TestEnumExtensions.ToEnum(stringValue); + } + break; + } + case JsonToken.Integer: + { + var numValue = reader.ReadAsInt32(); + if (numValue != null) + { + return (TestEnum)numValue.Value; + } + + break; + } + } + + return default; + } +} \ No newline at end of file diff --git a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/Filtering/SystemTextJson/_#JsonConverters.OneOf3.g.verified.cs b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/Filtering/SystemTextJson/_#JsonConverters.OneOf3.g.verified.cs index 2c5ba41477..5200f34d4a 100644 --- a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/Filtering/SystemTextJson/_#JsonConverters.OneOf3.g.verified.cs +++ b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/Filtering/SystemTextJson/_#JsonConverters.OneOf3.g.verified.cs @@ -17,7 +17,7 @@ public class OneOfJsonConverter : global::System.Text.Json.Serializa T1? value1 = default; try { - value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -27,7 +27,7 @@ public class OneOfJsonConverter : global::System.Text.Json.Serializa T2? value2 = default; try { - value2 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value2 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -37,7 +37,7 @@ public class OneOfJsonConverter : global::System.Text.Json.Serializa T3? value3 = default; try { - value3 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value3 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -56,17 +56,17 @@ public class OneOfJsonConverter : global::System.Text.Json.Serializa if (value1 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value2 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value3 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } return result; } diff --git a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/LangSmith/SystemTextJson/_#JsonConverters.AnyOf2.g.verified.cs b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/LangSmith/SystemTextJson/_#JsonConverters.AnyOf2.g.verified.cs index ec443cfda7..8f58669ce5 100644 --- a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/LangSmith/SystemTextJson/_#JsonConverters.AnyOf2.g.verified.cs +++ b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/LangSmith/SystemTextJson/_#JsonConverters.AnyOf2.g.verified.cs @@ -17,7 +17,7 @@ public class AnyOfJsonConverter : global::System.Text.Json.Serialization T1? value1 = default; try { - value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -27,7 +27,7 @@ public class AnyOfJsonConverter : global::System.Text.Json.Serialization T2? value2 = default; try { - value2 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value2 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -44,12 +44,12 @@ public class AnyOfJsonConverter : global::System.Text.Json.Serialization if (value1 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value2 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } return result; } diff --git a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/LangSmith/SystemTextJson/_#JsonConverters.AnyOf3.g.verified.cs b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/LangSmith/SystemTextJson/_#JsonConverters.AnyOf3.g.verified.cs index db710ecfdd..c7ddaccac7 100644 --- a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/LangSmith/SystemTextJson/_#JsonConverters.AnyOf3.g.verified.cs +++ b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/LangSmith/SystemTextJson/_#JsonConverters.AnyOf3.g.verified.cs @@ -17,7 +17,7 @@ public class AnyOfJsonConverter : global::System.Text.Json.Serializa T1? value1 = default; try { - value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -27,7 +27,7 @@ public class AnyOfJsonConverter : global::System.Text.Json.Serializa T2? value2 = default; try { - value2 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value2 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -37,7 +37,7 @@ public class AnyOfJsonConverter : global::System.Text.Json.Serializa T3? value3 = default; try { - value3 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value3 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -56,17 +56,17 @@ public class AnyOfJsonConverter : global::System.Text.Json.Serializa if (value1 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value2 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value3 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } return result; } diff --git a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/LangSmith/SystemTextJson/_#JsonConverters.AnyOf4.g.verified.cs b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/LangSmith/SystemTextJson/_#JsonConverters.AnyOf4.g.verified.cs index 6af1466f49..241aed50ba 100644 --- a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/LangSmith/SystemTextJson/_#JsonConverters.AnyOf4.g.verified.cs +++ b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/LangSmith/SystemTextJson/_#JsonConverters.AnyOf4.g.verified.cs @@ -17,7 +17,7 @@ public class AnyOfJsonConverter : global::System.Text.Json.Seria T1? value1 = default; try { - value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -27,7 +27,7 @@ public class AnyOfJsonConverter : global::System.Text.Json.Seria T2? value2 = default; try { - value2 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value2 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -37,7 +37,7 @@ public class AnyOfJsonConverter : global::System.Text.Json.Seria T3? value3 = default; try { - value3 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value3 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -47,7 +47,7 @@ public class AnyOfJsonConverter : global::System.Text.Json.Seria T4? value4 = default; try { - value4 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value4 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -68,22 +68,22 @@ public class AnyOfJsonConverter : global::System.Text.Json.Seria if (value1 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value2 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value3 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value4 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } return result; } diff --git a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/Ollama/SystemTextJson/_#JsonConverters.AnyOf2.g.verified.cs b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/Ollama/SystemTextJson/_#JsonConverters.AnyOf2.g.verified.cs index ec443cfda7..8f58669ce5 100644 --- a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/Ollama/SystemTextJson/_#JsonConverters.AnyOf2.g.verified.cs +++ b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/Ollama/SystemTextJson/_#JsonConverters.AnyOf2.g.verified.cs @@ -17,7 +17,7 @@ public class AnyOfJsonConverter : global::System.Text.Json.Serialization T1? value1 = default; try { - value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -27,7 +27,7 @@ public class AnyOfJsonConverter : global::System.Text.Json.Serialization T2? value2 = default; try { - value2 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value2 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -44,12 +44,12 @@ public class AnyOfJsonConverter : global::System.Text.Json.Serialization if (value1 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value2 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } return result; } diff --git a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.AnyOf1.g.verified.cs b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.AnyOf1.g.verified.cs index edbc8c8cf1..c6bb88fa09 100644 --- a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.AnyOf1.g.verified.cs +++ b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.AnyOf1.g.verified.cs @@ -17,7 +17,7 @@ public class AnyOfJsonConverter : global::System.Text.Json.Serialization.Jso T1? value1 = default; try { - value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -32,7 +32,7 @@ public class AnyOfJsonConverter : global::System.Text.Json.Serialization.Jso if (value1 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } return result; } diff --git a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.AnyOf2.g.verified.cs b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.AnyOf2.g.verified.cs index ec443cfda7..8f58669ce5 100644 --- a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.AnyOf2.g.verified.cs +++ b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.AnyOf2.g.verified.cs @@ -17,7 +17,7 @@ public class AnyOfJsonConverter : global::System.Text.Json.Serialization T1? value1 = default; try { - value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -27,7 +27,7 @@ public class AnyOfJsonConverter : global::System.Text.Json.Serialization T2? value2 = default; try { - value2 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value2 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -44,12 +44,12 @@ public class AnyOfJsonConverter : global::System.Text.Json.Serialization if (value1 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value2 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } return result; } diff --git a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf1.g.verified.cs b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf1.g.verified.cs index d328340718..e0077123d7 100644 --- a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf1.g.verified.cs +++ b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf1.g.verified.cs @@ -17,7 +17,7 @@ public class OneOfJsonConverter : global::System.Text.Json.Serialization.Jso T1? value1 = default; try { - value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -32,7 +32,7 @@ public class OneOfJsonConverter : global::System.Text.Json.Serialization.Jso if (value1 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } return result; } diff --git a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf2.g.verified.cs b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf2.g.verified.cs index dfb776a456..eaae26fe19 100644 --- a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf2.g.verified.cs +++ b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf2.g.verified.cs @@ -17,7 +17,7 @@ public class OneOfJsonConverter : global::System.Text.Json.Serialization T1? value1 = default; try { - value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -27,7 +27,7 @@ public class OneOfJsonConverter : global::System.Text.Json.Serialization T2? value2 = default; try { - value2 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value2 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -44,12 +44,12 @@ public class OneOfJsonConverter : global::System.Text.Json.Serialization if (value1 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value2 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } return result; } diff --git a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf3.g.verified.cs b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf3.g.verified.cs index 2c5ba41477..5200f34d4a 100644 --- a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf3.g.verified.cs +++ b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf3.g.verified.cs @@ -17,7 +17,7 @@ public class OneOfJsonConverter : global::System.Text.Json.Serializa T1? value1 = default; try { - value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -27,7 +27,7 @@ public class OneOfJsonConverter : global::System.Text.Json.Serializa T2? value2 = default; try { - value2 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value2 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -37,7 +37,7 @@ public class OneOfJsonConverter : global::System.Text.Json.Serializa T3? value3 = default; try { - value3 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value3 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -56,17 +56,17 @@ public class OneOfJsonConverter : global::System.Text.Json.Serializa if (value1 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value2 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value3 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } return result; } diff --git a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf4.g.verified.cs b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf4.g.verified.cs index 1ed1e3f4a3..bfc23191df 100644 --- a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf4.g.verified.cs +++ b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf4.g.verified.cs @@ -17,7 +17,7 @@ public class OneOfJsonConverter : global::System.Text.Json.Seria T1? value1 = default; try { - value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -27,7 +27,7 @@ public class OneOfJsonConverter : global::System.Text.Json.Seria T2? value2 = default; try { - value2 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value2 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -37,7 +37,7 @@ public class OneOfJsonConverter : global::System.Text.Json.Seria T3? value3 = default; try { - value3 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value3 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -47,7 +47,7 @@ public class OneOfJsonConverter : global::System.Text.Json.Seria T4? value4 = default; try { - value4 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value4 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -68,22 +68,22 @@ public class OneOfJsonConverter : global::System.Text.Json.Seria if (value1 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value2 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value3 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value4 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } return result; } diff --git a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf5.g.verified.cs b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf5.g.verified.cs index ba537b3bd7..f4e2b1edd4 100644 --- a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf5.g.verified.cs +++ b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf5.g.verified.cs @@ -17,7 +17,7 @@ public class OneOfJsonConverter : global::System.Text.Json.S T1? value1 = default; try { - value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -27,7 +27,7 @@ public class OneOfJsonConverter : global::System.Text.Json.S T2? value2 = default; try { - value2 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value2 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -37,7 +37,7 @@ public class OneOfJsonConverter : global::System.Text.Json.S T3? value3 = default; try { - value3 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value3 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -47,7 +47,7 @@ public class OneOfJsonConverter : global::System.Text.Json.S T4? value4 = default; try { - value4 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value4 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -57,7 +57,7 @@ public class OneOfJsonConverter : global::System.Text.Json.S T5? value5 = default; try { - value5 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value5 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -80,27 +80,27 @@ public class OneOfJsonConverter : global::System.Text.Json.S if (value1 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value2 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value3 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value4 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value5 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } return result; } diff --git a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf6.g.verified.cs b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf6.g.verified.cs index 2dd0a00c95..5cd0b68b7c 100644 --- a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf6.g.verified.cs +++ b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf6.g.verified.cs @@ -17,7 +17,7 @@ public class OneOfJsonConverter : global::System.Text.Js T1? value1 = default; try { - value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -27,7 +27,7 @@ public class OneOfJsonConverter : global::System.Text.Js T2? value2 = default; try { - value2 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value2 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -37,7 +37,7 @@ public class OneOfJsonConverter : global::System.Text.Js T3? value3 = default; try { - value3 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value3 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -47,7 +47,7 @@ public class OneOfJsonConverter : global::System.Text.Js T4? value4 = default; try { - value4 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value4 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -57,7 +57,7 @@ public class OneOfJsonConverter : global::System.Text.Js T5? value5 = default; try { - value5 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value5 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -67,7 +67,7 @@ public class OneOfJsonConverter : global::System.Text.Js T6? value6 = default; try { - value6 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value6 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -92,32 +92,32 @@ public class OneOfJsonConverter : global::System.Text.Js if (value1 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value2 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value3 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value4 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value5 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value6 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } return result; } diff --git a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf7.g.verified.cs b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf7.g.verified.cs index 06277f02a8..519fd04c25 100644 --- a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf7.g.verified.cs +++ b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf7.g.verified.cs @@ -17,7 +17,7 @@ public class OneOfJsonConverter : global::System.Tex T1? value1 = default; try { - value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -27,7 +27,7 @@ public class OneOfJsonConverter : global::System.Tex T2? value2 = default; try { - value2 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value2 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -37,7 +37,7 @@ public class OneOfJsonConverter : global::System.Tex T3? value3 = default; try { - value3 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value3 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -47,7 +47,7 @@ public class OneOfJsonConverter : global::System.Tex T4? value4 = default; try { - value4 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value4 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -57,7 +57,7 @@ public class OneOfJsonConverter : global::System.Tex T5? value5 = default; try { - value5 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value5 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -67,7 +67,7 @@ public class OneOfJsonConverter : global::System.Tex T6? value6 = default; try { - value6 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value6 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -77,7 +77,7 @@ public class OneOfJsonConverter : global::System.Tex T7? value7 = default; try { - value7 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value7 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -104,37 +104,37 @@ public class OneOfJsonConverter : global::System.Tex if (value1 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value2 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value3 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value4 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value5 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value6 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value7 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } return result; } diff --git a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf9.g.verified.cs b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf9.g.verified.cs index 89ca5d9492..c6bd9d96cd 100644 --- a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf9.g.verified.cs +++ b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#JsonConverters.OneOf9.g.verified.cs @@ -17,7 +17,7 @@ public class OneOfJsonConverter : global::Sy T1? value1 = default; try { - value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -27,7 +27,7 @@ public class OneOfJsonConverter : global::Sy T2? value2 = default; try { - value2 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value2 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -37,7 +37,7 @@ public class OneOfJsonConverter : global::Sy T3? value3 = default; try { - value3 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value3 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -47,7 +47,7 @@ public class OneOfJsonConverter : global::Sy T4? value4 = default; try { - value4 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value4 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -57,7 +57,7 @@ public class OneOfJsonConverter : global::Sy T5? value5 = default; try { - value5 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value5 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -67,7 +67,7 @@ public class OneOfJsonConverter : global::Sy T6? value6 = default; try { - value6 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value6 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -77,7 +77,7 @@ public class OneOfJsonConverter : global::Sy T7? value7 = default; try { - value7 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value7 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -87,7 +87,7 @@ public class OneOfJsonConverter : global::Sy T8? value8 = default; try { - value8 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value8 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -97,7 +97,7 @@ public class OneOfJsonConverter : global::Sy T9? value9 = default; try { - value9 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy); + value9 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, options); } catch (global::System.Text.Json.JsonException) { @@ -128,47 +128,47 @@ public class OneOfJsonConverter : global::Sy if (value1 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value2 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value3 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value4 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value5 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value6 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value7 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value8 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } else if (value9 != null) { - _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader); + _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); } return result; } diff --git a/src/tests/OpenApiGenerator.UnitTests/JsonTests.Enum.AnyOf.cs b/src/tests/OpenApiGenerator.UnitTests/JsonTests.Enum.AnyOf.cs new file mode 100644 index 0000000000..1f72666e6f --- /dev/null +++ b/src/tests/OpenApiGenerator.UnitTests/JsonTests.Enum.AnyOf.cs @@ -0,0 +1,64 @@ +using System.Text.Json; +using OpenApiGenerator.JsonConverters; +using JsonSerializer = System.Text.Json.JsonSerializer; + +namespace OpenApiGenerator.UnitTests; + +public partial class JsonTests +{ + [TestMethod] + public void Enum2_AnyOfStringAndEnum_SystemTextJson_String() + { + const string json = "{\"status\":\"pulling 797b70c4edf8\",\"digest\":\"sha256:797b70c4edf85907fe0a49eb85811256f65fa0f7bf52166b147fd16be2be4662\",\"total\":45949216}"; + + var response = JsonSerializer.Deserialize(json); + response.Should().NotBeNull(); + response!.Status.Value1.Should().Be(null); + response!.Status.Value2.Should().Be("pulling 797b70c4edf8"); + response!.Status.Object.Should().Be("pulling 797b70c4edf8"); + + var responseReverted = JsonSerializer.Deserialize(json); + responseReverted.Should().NotBeNull(); + responseReverted!.Status.Value2.Should().Be(null); + responseReverted!.Status.Value1.Should().Be("pulling 797b70c4edf8"); + response!.Status.Object.Should().Be("pulling 797b70c4edf8"); + } + + [TestMethod] + public void Enum2_AnyOfStringAndEnum_SystemTextJson_Enum() + { + const string json = "{\"status\":\"pulling manifest\",\"digest\":\"sha256:797b70c4edf85907fe0a49eb85811256f65fa0f7bf52166b147fd16be2be4662\",\"total\":45949216}"; + + var response = JsonSerializer.Deserialize(json, new JsonSerializerOptions + { + Converters = { new AnyOfConverterFactorySystemTextJson(), new TestEnumJsonStringEnumConverter() } + }); + response.Should().NotBeNull(); + response!.Status.Value1.Should().Be(TestEnum.PullingManifest); + response!.Status.Value2.Should().Be("pulling manifest"); + response!.Status.Object.Should().Be("pulling manifest"); + + var responseReverted = JsonSerializer.Deserialize(json, new JsonSerializerOptions + { + Converters = { new AnyOfConverterFactorySystemTextJson(), new TestEnumJsonStringEnumConverter() } + }); + responseReverted.Should().NotBeNull(); + responseReverted!.Status.Value2.Should().Be(TestEnum.PullingManifest); + responseReverted!.Status.Value1.Should().Be("pulling manifest"); + responseReverted!.Status.Object.Should().Be(TestEnum.PullingManifest); + } +} + +public sealed partial class TestEnumClassAnyOf +{ + [global::System.Text.Json.Serialization.JsonPropertyName("status")] + [global::System.Text.Json.Serialization.JsonConverter(typeof(AnyOfConverterFactorySystemTextJson))] + public AnyOf Status { get; set; } +} + +public sealed partial class TestEnumClassAnyOfReverted +{ + [global::System.Text.Json.Serialization.JsonPropertyName("status")] + [global::System.Text.Json.Serialization.JsonConverter(typeof(AnyOfConverterFactorySystemTextJson))] + public AnyOf Status { get; set; } +} \ No newline at end of file diff --git a/src/tests/OpenApiGenerator.UnitTests/JsonTests.Enum.New.cs b/src/tests/OpenApiGenerator.UnitTests/JsonTests.Enum.New.cs index bb3799d36e..bc8aef92a8 100644 --- a/src/tests/OpenApiGenerator.UnitTests/JsonTests.Enum.New.cs +++ b/src/tests/OpenApiGenerator.UnitTests/JsonTests.Enum.New.cs @@ -1,6 +1,5 @@ -using System.Text.Json; -using System.Text.Json.Serialization; -using Newtonsoft.Json; +using System.Text.Json.Serialization; +using OpenApiGenerator.JsonConverters; using JsonSerializer = System.Text.Json.JsonSerializer; namespace OpenApiGenerator.UnitTests; @@ -42,123 +41,3 @@ public void Enum2_SystemTextJson_SourceGenerationContext() [JsonSourceGenerationOptions(DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] [JsonSerializable(typeof(TestEnumClass))] internal sealed partial class TestSourceGenerationContext : JsonSerializerContext; - -public sealed partial class TestEnumClass -{ - [global::System.Text.Json.Serialization.JsonPropertyName("status")] - [global::System.Text.Json.Serialization.JsonConverter(typeof(TestEnumJsonStringEnumConverter))] - public TestEnum? Status { get; set; } -} - -public enum TestEnum -{ - PullingManifest, - Success, -} - -public static class TestEnumExtensions -{ - public static string ToValueString(this TestEnum value) - { - return value switch - { - TestEnum.PullingManifest => "pulling manifest", - TestEnum.Success => "success", - _ => throw new ArgumentOutOfRangeException(nameof(value), value, null), - }; - } - - public static TestEnum ToEnum(string value) - { - return value switch - { - "pulling manifest" => TestEnum.PullingManifest, - "success" => TestEnum.Success, - _ => throw new ArgumentOutOfRangeException(nameof(value), value, null), - }; - } -} - -internal sealed class TestEnumJsonStringEnumConverter : global::System.Text.Json.Serialization.JsonConverter -{ - public override TestEnum Read( - ref global::System.Text.Json.Utf8JsonReader reader, - global::System.Type typeToConvert, - global::System.Text.Json.JsonSerializerOptions options) - { - switch (reader.TokenType) - { - case global::System.Text.Json.JsonTokenType.String: - { - var stringValue = reader.GetString(); - if (stringValue != null) - { - return TestEnumExtensions.ToEnum(stringValue); - } - - break; - } - case global::System.Text.Json.JsonTokenType.Number: - { - return (TestEnum)reader.GetInt32(); - } - default: - throw new global::System.ArgumentOutOfRangeException(); - } - - return default; - } - - public override void Write( - global::System.Text.Json.Utf8JsonWriter writer, - TestEnum value, - global::System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.ToValueString()); - } -} - - -internal sealed class TestEnumNewtonsoftJsonStringEnumConverter : Newtonsoft.Json.JsonConverter -{ - public override void WriteJson(JsonWriter writer, TestEnum value, Newtonsoft.Json.JsonSerializer serializer) - { - writer.WriteValue(value.ToValueString()); - } - - public override TestEnum ReadJson(JsonReader reader, Type objectType, TestEnum existingValue, bool hasExistingValue, - Newtonsoft.Json.JsonSerializer serializer) - { - if (hasExistingValue) - { - return existingValue; - } - - var type = reader.TokenType; - - switch (type) - { - case JsonToken.String: - { - var stringValue = reader.ReadAsString(); - if (stringValue != null) - { - return TestEnumExtensions.ToEnum(stringValue); - } - break; - } - case JsonToken.Integer: - { - var numValue = reader.ReadAsInt32(); - if (numValue != null) - { - return (TestEnum)numValue.Value; - } - - break; - } - } - - return default; - } -} \ No newline at end of file