openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
OpenAI.Responses/src/Generated/Models/ApplyPatchDeleteFileOperation.Serialization.cs
127lines · 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 ApplyPatchDeleteFileOperation : ApplyPatchOperation, IJsonModel<ApplyPatchDeleteFileOperation> |
| 14 | { |
| 15 | internal ApplyPatchDeleteFileOperation() : this(InternalApplyPatchOperationType.DeleteFile, default, null) |
| 16 | { |
| 17 | } |
| 18 | |
| 19 | protected override ApplyPatchOperation PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) |
| 20 | { |
| 21 | string format = options.Format == "W" ? ((IPersistableModel<ApplyPatchDeleteFileOperation>)this).GetFormatFromOptions(options) : options.Format; |
| 22 | switch (format) |
| 23 | { |
| 24 | case "J": |
| 25 | using (JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions)) |
| 26 | { |
| 27 | return DeserializeApplyPatchDeleteFileOperation(document.RootElement, data, options); |
| 28 | } |
| 29 | default: |
| 30 | throw new FormatException($"The model {nameof(ApplyPatchDeleteFileOperation)} 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<ApplyPatchDeleteFileOperation>)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(ApplyPatchDeleteFileOperation)} does not support writing '{options.Format}' format."); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | BinaryData IPersistableModel<ApplyPatchDeleteFileOperation>.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); |
| 47 | |
| 48 | ApplyPatchDeleteFileOperation IPersistableModel<ApplyPatchDeleteFileOperation>.Create(BinaryData data, ModelReaderWriterOptions options) => (ApplyPatchDeleteFileOperation)PersistableModelCreateCore(data, options); |
| 49 | |
| 50 | string IPersistableModel<ApplyPatchDeleteFileOperation>.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; |
| 51 | |
| 52 | void IJsonModel<ApplyPatchDeleteFileOperation>.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<ApplyPatchDeleteFileOperation>)this).GetFormatFromOptions(options) : options.Format; |
| 70 | if (format != "J") |
| 71 | { |
| 72 | throw new FormatException($"The model {nameof(ApplyPatchDeleteFileOperation)} 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("$.path"u8)) |
| 77 | { |
| 78 | writer.WritePropertyName("path"u8); |
| 79 | writer.WriteStringValue(FilePath); |
| 80 | } |
| 81 | |
| 82 | Patch.WriteTo(writer); |
| 83 | #pragma warning restore SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates. |
| 84 | } |
| 85 | |
| 86 | ApplyPatchDeleteFileOperation IJsonModel<ApplyPatchDeleteFileOperation>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => (ApplyPatchDeleteFileOperation)JsonModelCreateCore(ref reader, options); |
| 87 | |
| 88 | protected override ApplyPatchOperation JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) |
| 89 | { |
| 90 | string format = options.Format == "W" ? ((IPersistableModel<ApplyPatchDeleteFileOperation>)this).GetFormatFromOptions(options) : options.Format; |
| 91 | if (format != "J") |
| 92 | { |
| 93 | throw new FormatException($"The model {nameof(ApplyPatchDeleteFileOperation)} does not support reading '{format}' format."); |
| 94 | } |
| 95 | using JsonDocument document = JsonDocument.ParseValue(ref reader); |
| 96 | return DeserializeApplyPatchDeleteFileOperation(document.RootElement, null, options); |
| 97 | } |
| 98 | |
| 99 | internal static ApplyPatchDeleteFileOperation DeserializeApplyPatchDeleteFileOperation(JsonElement element, BinaryData data, ModelReaderWriterOptions options) |
| 100 | { |
| 101 | if (element.ValueKind == JsonValueKind.Null) |
| 102 | { |
| 103 | return null; |
| 104 | } |
| 105 | InternalApplyPatchOperationType kind = default; |
| 106 | #pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates. |
| 107 | JsonPatch patch = new JsonPatch(data is null ? ReadOnlyMemory<byte>.Empty : data.ToMemory()); |
| 108 | #pragma warning restore SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates. |
| 109 | string filePath = default; |
| 110 | foreach (var prop in element.EnumerateObject()) |
| 111 | { |
| 112 | if (prop.NameEquals("type"u8)) |
| 113 | { |
| 114 | kind = new InternalApplyPatchOperationType(prop.Value.GetString()); |
| 115 | continue; |
| 116 | } |
| 117 | if (prop.NameEquals("path"u8)) |
| 118 | { |
| 119 | filePath = prop.Value.GetString(); |
| 120 | continue; |
| 121 | } |
| 122 | patch.Set([.. "$."u8, .. Encoding.UTF8.GetBytes(prop.Name)], prop.Value.GetUtf8Bytes()); |
| 123 | } |
| 124 | return new ApplyPatchDeleteFileOperation(kind, patch, filePath); |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | |