openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
OpenAI.Responses/src/Generated/Models/ApplyPatchCallOutputItem.Serialization.cs
178lines · modecode
| 1 | // <auto-generated/> |
| 2 | |
| 3 | #nullable disable |
| 4 | |
| 5 | using System; |
| 6 | using System.ClientModel.Primitives; |
| 7 | using System.Text; |
| 8 | using System.Text.Json; |
| 9 | using OpenAI; |
| 10 | |
| 11 | namespace OpenAI.Responses |
| 12 | { |
| 13 | public partial class ApplyPatchCallOutputItem : ResponseItem, IJsonModel<ApplyPatchCallOutputItem> |
| 14 | { |
| 15 | internal ApplyPatchCallOutputItem() : this(ResponseItemKind.ApplyPatchCallOutput, null, default, null, default, null, null) |
| 16 | { |
| 17 | } |
| 18 | |
| 19 | protected override ResponseItem PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) |
| 20 | { |
| 21 | string format = options.Format == "W" ? ((IPersistableModel<ApplyPatchCallOutputItem>)this).GetFormatFromOptions(options) : options.Format; |
| 22 | switch (format) |
| 23 | { |
| 24 | case "J": |
| 25 | using (JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions)) |
| 26 | { |
| 27 | return DeserializeApplyPatchCallOutputItem(document.RootElement, data, options); |
| 28 | } |
| 29 | default: |
| 30 | throw new FormatException($"The model {nameof(ApplyPatchCallOutputItem)} does not support reading '{options.Format}' format."); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | protected override BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) |
| 35 | { |
| 36 | string format = options.Format == "W" ? ((IPersistableModel<ApplyPatchCallOutputItem>)this).GetFormatFromOptions(options) : options.Format; |
| 37 | switch (format) |
| 38 | { |
| 39 | case "J": |
| 40 | return ModelReaderWriter.Write(this, options, OpenAIContext.Default); |
| 41 | default: |
| 42 | throw new FormatException($"The model {nameof(ApplyPatchCallOutputItem)} does not support writing '{options.Format}' format."); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | BinaryData IPersistableModel<ApplyPatchCallOutputItem>.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); |
| 47 | |
| 48 | ApplyPatchCallOutputItem IPersistableModel<ApplyPatchCallOutputItem>.Create(BinaryData data, ModelReaderWriterOptions options) => (ApplyPatchCallOutputItem)PersistableModelCreateCore(data, options); |
| 49 | |
| 50 | string IPersistableModel<ApplyPatchCallOutputItem>.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; |
| 51 | |
| 52 | void IJsonModel<ApplyPatchCallOutputItem>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) |
| 53 | { |
| 54 | #pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates. |
| 55 | if (Patch.Contains("$"u8)) |
| 56 | { |
| 57 | writer.WriteRawValue(Patch.GetJson("$"u8)); |
| 58 | return; |
| 59 | } |
| 60 | #pragma warning restore SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates. |
| 61 | |
| 62 | writer.WriteStartObject(); |
| 63 | JsonModelWriteCore(writer, options); |
| 64 | writer.WriteEndObject(); |
| 65 | } |
| 66 | |
| 67 | protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) |
| 68 | { |
| 69 | string format = options.Format == "W" ? ((IPersistableModel<ApplyPatchCallOutputItem>)this).GetFormatFromOptions(options) : options.Format; |
| 70 | if (format != "J") |
| 71 | { |
| 72 | throw new FormatException($"The model {nameof(ApplyPatchCallOutputItem)} does not support writing '{format}' format."); |
| 73 | } |
| 74 | base.JsonModelWriteCore(writer, options); |
| 75 | #pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates. |
| 76 | if (!Patch.Contains("$.call_id"u8)) |
| 77 | { |
| 78 | writer.WritePropertyName("call_id"u8); |
| 79 | writer.WriteStringValue(CallId); |
| 80 | } |
| 81 | if (!Patch.Contains("$.status"u8)) |
| 82 | { |
| 83 | writer.WritePropertyName("status"u8); |
| 84 | writer.WriteStringValue(Status.ToString()); |
| 85 | } |
| 86 | if (Optional.IsDefined(Output) && !Patch.Contains("$.output"u8)) |
| 87 | { |
| 88 | writer.WritePropertyName("output"u8); |
| 89 | writer.WriteStringValue(Output); |
| 90 | } |
| 91 | if (Optional.IsDefined(CreatedBy) && !Patch.Contains("$.created_by"u8)) |
| 92 | { |
| 93 | writer.WritePropertyName("created_by"u8); |
| 94 | writer.WriteStringValue(CreatedBy); |
| 95 | } |
| 96 | |
| 97 | Patch.WriteTo(writer); |
| 98 | #pragma warning restore SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates. |
| 99 | } |
| 100 | |
| 101 | ApplyPatchCallOutputItem IJsonModel<ApplyPatchCallOutputItem>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => (ApplyPatchCallOutputItem)JsonModelCreateCore(ref reader, options); |
| 102 | |
| 103 | protected override ResponseItem JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) |
| 104 | { |
| 105 | string format = options.Format == "W" ? ((IPersistableModel<ApplyPatchCallOutputItem>)this).GetFormatFromOptions(options) : options.Format; |
| 106 | if (format != "J") |
| 107 | { |
| 108 | throw new FormatException($"The model {nameof(ApplyPatchCallOutputItem)} does not support reading '{format}' format."); |
| 109 | } |
| 110 | using JsonDocument document = JsonDocument.ParseValue(ref reader); |
| 111 | return DeserializeApplyPatchCallOutputItem(document.RootElement, null, options); |
| 112 | } |
| 113 | |
| 114 | internal static ApplyPatchCallOutputItem DeserializeApplyPatchCallOutputItem(JsonElement element, BinaryData data, ModelReaderWriterOptions options) |
| 115 | { |
| 116 | if (element.ValueKind == JsonValueKind.Null) |
| 117 | { |
| 118 | return null; |
| 119 | } |
| 120 | ResponseItemKind kind = default; |
| 121 | string id = default; |
| 122 | #pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates. |
| 123 | JsonPatch patch = new JsonPatch(data is null ? ReadOnlyMemory<byte>.Empty : data.ToMemory()); |
| 124 | #pragma warning restore SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates. |
| 125 | string callId = default; |
| 126 | ApplyPatchCallOutputStatus status = default; |
| 127 | string output = default; |
| 128 | string createdBy = default; |
| 129 | foreach (var prop in element.EnumerateObject()) |
| 130 | { |
| 131 | if (prop.NameEquals("type"u8)) |
| 132 | { |
| 133 | kind = new ResponseItemKind(prop.Value.GetString()); |
| 134 | continue; |
| 135 | } |
| 136 | if (prop.NameEquals("id"u8)) |
| 137 | { |
| 138 | id = prop.Value.GetString(); |
| 139 | continue; |
| 140 | } |
| 141 | if (prop.NameEquals("call_id"u8)) |
| 142 | { |
| 143 | callId = prop.Value.GetString(); |
| 144 | continue; |
| 145 | } |
| 146 | if (prop.NameEquals("status"u8)) |
| 147 | { |
| 148 | status = new ApplyPatchCallOutputStatus(prop.Value.GetString()); |
| 149 | continue; |
| 150 | } |
| 151 | if (prop.NameEquals("output"u8)) |
| 152 | { |
| 153 | if (prop.Value.ValueKind == JsonValueKind.Null) |
| 154 | { |
| 155 | output = null; |
| 156 | continue; |
| 157 | } |
| 158 | output = prop.Value.GetString(); |
| 159 | continue; |
| 160 | } |
| 161 | if (prop.NameEquals("created_by"u8)) |
| 162 | { |
| 163 | createdBy = prop.Value.GetString(); |
| 164 | continue; |
| 165 | } |
| 166 | patch.Set([.. "$."u8, .. Encoding.UTF8.GetBytes(prop.Name)], prop.Value.GetUtf8Bytes()); |
| 167 | } |
| 168 | return new ApplyPatchCallOutputItem( |
| 169 | kind, |
| 170 | id, |
| 171 | patch, |
| 172 | callId, |
| 173 | status, |
| 174 | output, |
| 175 | createdBy); |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | |