55using System ;
66using System . ClientModel . Primitives ;
77using System . Collections . Generic ;
8+ using System . Text ;
89using System . Text . Json ;
910using OpenAI ;
1011
@@ -14,6 +15,14 @@ public partial class WebSearchToolFilters : IJsonModel<WebSearchToolFilters>
1415 {
1516 void IJsonModel < WebSearchToolFilters > . Write ( Utf8JsonWriter writer , ModelReaderWriterOptions options )
1617 {
18+ #pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
19+ if ( Patch . Contains ( "$"u8 ) )
20+ {
21+ writer . WriteRawValue ( Patch . GetJson ( "$"u8 ) ) ;
22+ return ;
23+ }
24+ #pragma warning restore SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
25+
1726 writer . WriteStartObject ( ) ;
1827 JsonModelWriteCore ( writer , options ) ;
1928 writer . WriteEndObject ( ) ;
@@ -26,41 +35,38 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit
2635 {
2736 throw new FormatException ( $ "The model { nameof ( WebSearchToolFilters ) } does not support writing '{ format } ' format.") ;
2837 }
29- if ( Optional . IsCollectionDefined ( AllowedDomains ) && _additionalBinaryDataProperties ? . ContainsKey ( "allowed_domains" ) != true )
38+ #pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
39+ if ( Patch . Contains ( "$.allowed_domains"u8 ) )
3040 {
31- writer . WritePropertyName ( "allowed_domains"u8 ) ;
32- writer . WriteStartArray ( ) ;
33- foreach ( string item in AllowedDomains )
41+ if ( ! Patch . IsRemoved ( "$.allowed_domains"u8 ) )
3442 {
35- if ( item == null )
36- {
37- writer . WriteNullValue ( ) ;
38- continue ;
39- }
40- writer . WriteStringValue ( item ) ;
43+ writer . WritePropertyName ( "allowed_domains"u8 ) ;
44+ writer . WriteRawValue ( Patch . GetJson ( "$.allowed_domains"u8 ) ) ;
4145 }
42- writer . WriteEndArray ( ) ;
4346 }
44- // Plugin customization: remove options.Format != "W" check
45- if ( _additionalBinaryDataProperties != null )
47+ else if ( Optional . IsCollectionDefined ( AllowedDomains ) )
4648 {
47- foreach ( var item in _additionalBinaryDataProperties )
49+ writer . WritePropertyName ( "allowed_domains"u8 ) ;
50+ writer . WriteStartArray ( ) ;
51+ for ( int i = 0 ; i < AllowedDomains . Count ; i ++ )
4852 {
49- if ( ModelSerializationExtensions . IsSentinelValue ( item . Value ) )
53+ if ( Patch . IsRemoved ( Encoding . UTF8 . GetBytes ( $ "$.allowed_domains[ { i } ]" ) ) )
5054 {
5155 continue ;
5256 }
53- writer . WritePropertyName ( item . Key ) ;
54- #if NET6_0_OR_GREATER
55- writer . WriteRawValue ( item . Value ) ;
56- #else
57- using ( JsonDocument document = JsonDocument . Parse ( item . Value ) )
57+ if ( AllowedDomains [ i ] == null )
5858 {
59- JsonSerializer . Serialize ( writer , document . RootElement ) ;
59+ writer . WriteNullValue ( ) ;
60+ continue ;
6061 }
61- #endif
62+ writer . WriteStringValue ( AllowedDomains [ i ] ) ;
6263 }
64+ Patch . WriteTo ( writer , "$.allowed_domains"u8 ) ;
65+ writer . WriteEndArray ( ) ;
6366 }
67+
68+ Patch . WriteTo ( writer ) ;
69+ #pragma warning restore SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
6470 }
6571
6672 WebSearchToolFilters IJsonModel < WebSearchToolFilters > . Create ( ref Utf8JsonReader reader , ModelReaderWriterOptions options ) => JsonModelCreateCore ( ref reader , options ) ;
@@ -73,17 +79,19 @@ protected virtual WebSearchToolFilters JsonModelCreateCore(ref Utf8JsonReader re
7379 throw new FormatException ( $ "The model { nameof ( WebSearchToolFilters ) } does not support reading '{ format } ' format.") ;
7480 }
7581 using JsonDocument document = JsonDocument . ParseValue ( ref reader ) ;
76- return DeserializeWebSearchToolFilters ( document . RootElement , options ) ;
82+ return DeserializeWebSearchToolFilters ( document . RootElement , null , options ) ;
7783 }
7884
79- internal static WebSearchToolFilters DeserializeWebSearchToolFilters ( JsonElement element , ModelReaderWriterOptions options )
85+ internal static WebSearchToolFilters DeserializeWebSearchToolFilters ( JsonElement element , BinaryData data , ModelReaderWriterOptions options )
8086 {
8187 if ( element . ValueKind == JsonValueKind . Null )
8288 {
8389 return null ;
8490 }
8591 IList < string > allowedDomains = default ;
86- IDictionary < string , BinaryData > additionalBinaryDataProperties = new ChangeTrackingDictionary < string , BinaryData > ( ) ;
92+ #pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
93+ JsonPatch patch = new JsonPatch ( data is null ? ReadOnlyMemory < byte > . Empty : data . ToMemory ( ) ) ;
94+ #pragma warning restore SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
8795 foreach ( var prop in element . EnumerateObject ( ) )
8896 {
8997 if ( prop . NameEquals ( "allowed_domains"u8 ) )
@@ -107,10 +115,9 @@ internal static WebSearchToolFilters DeserializeWebSearchToolFilters(JsonElement
107115 allowedDomains = array ;
108116 continue ;
109117 }
110- // Plugin customization: remove options.Format != "W" check
111- additionalBinaryDataProperties . Add ( prop . Name , BinaryData . FromString ( prop . Value . GetRawText ( ) ) ) ;
118+ patch . Set ( [ .. "$."u8 , .. Encoding . UTF8 . GetBytes ( prop . Name ) ] , prop . Value . GetUtf8Bytes ( ) ) ;
112119 }
113- return new WebSearchToolFilters ( allowedDomains ?? new ChangeTrackingList < string > ( ) , additionalBinaryDataProperties ) ;
120+ return new WebSearchToolFilters ( allowedDomains ?? new ChangeTrackingList < string > ( ) , patch ) ;
114121 }
115122
116123 BinaryData IPersistableModel < WebSearchToolFilters > . Write ( ModelReaderWriterOptions options ) => PersistableModelWriteCore ( options ) ;
@@ -137,7 +144,7 @@ protected virtual WebSearchToolFilters PersistableModelCreateCore(BinaryData dat
137144 case "J" :
138145 using ( JsonDocument document = JsonDocument . Parse ( data ) )
139146 {
140- return DeserializeWebSearchToolFilters ( document . RootElement , options ) ;
147+ return DeserializeWebSearchToolFilters ( document . RootElement , data , options ) ;
141148 }
142149 default :
143150 throw new FormatException ( $ "The model { nameof ( WebSearchToolFilters ) } does not support reading '{ options . Format } ' format.") ;
0 commit comments