@@ -757,6 +757,111 @@ public void CELFieldTransformWithNullable()
757
757
Assert . Equal ( user . FavoriteNumber , result . FavoriteNumber ) ;
758
758
}
759
759
760
+ [ Fact ]
761
+ public void CELFieldTransformWithUnionOfRefs ( )
762
+ {
763
+ var schemaStr = @"{
764
+ ""type"": ""object"",
765
+ ""properties"": {
766
+ ""messageType"": {
767
+ ""type"": ""string""
768
+ },
769
+ ""version"": {
770
+ ""type"": ""string""
771
+ },
772
+ ""payload"": {
773
+ ""type"": ""object"",
774
+ ""oneOf"": [
775
+ {
776
+ ""$ref"": ""#/$defs/authentication_request""
777
+ },
778
+ {
779
+ ""$ref"": ""#/$defs/authentication_status""
780
+ }
781
+ ]
782
+ }
783
+ },
784
+ ""required"": [
785
+ ""payload"",
786
+ ""messageType"",
787
+ ""version""
788
+ ],
789
+ ""$defs"": {
790
+ ""authentication_request"": {
791
+ ""properties"": {
792
+ ""messageId"": {
793
+ ""type"": ""string"",
794
+ ""confluent:tags"": [""PII""]
795
+ },
796
+ ""timestamp"": {
797
+ ""type"": ""integer"",
798
+ ""minimum"": 0
799
+ },
800
+ ""requestId"": {
801
+ ""type"": ""string""
802
+ }
803
+ },
804
+ ""required"": [
805
+ ""messageId"",
806
+ ""timestamp""
807
+ ]
808
+ },
809
+ ""authentication_status"": {
810
+ ""properties"": {
811
+ ""messageId"": {
812
+ ""type"": ""string"",
813
+ ""confluent:tags"": [""PII""]
814
+ },
815
+ ""authType"": {
816
+ ""type"": [
817
+ ""string"",
818
+ ""null""
819
+ ]
820
+ }
821
+ },
822
+ ""required"": [
823
+ ""messageId"",
824
+ ""authType""
825
+ ]
826
+ }
827
+ }
828
+ }" ;
829
+ var schema = new RegisteredSchema ( "topic-value" , 1 , 1 , schemaStr , SchemaType . Json , null ) ;
830
+ schema . RuleSet = new RuleSet ( new List < Rule > ( ) ,
831
+ new List < Rule >
832
+ {
833
+ new Rule ( "testCEL" , RuleKind . Transform , RuleMode . Write , "CEL_FIELD" , null , null ,
834
+ "typeName == 'STRING' ; value + '-suffix'" , null , null , false )
835
+ }
836
+ ) ;
837
+ store [ schemaStr ] = 1 ;
838
+ subjectStore [ "topic-value" ] = new List < RegisteredSchema > { schema } ;
839
+ var config = new JsonSerializerConfig
840
+ {
841
+ AutoRegisterSchemas = false ,
842
+ UseLatestVersion = true
843
+ } ;
844
+ var serializer = new JsonSerializer < Message > ( schemaRegistryClient , config ) ;
845
+ var deserializer = new JsonDeserializer < Message > ( schemaRegistryClient ) ;
846
+
847
+ var msg = new Message
848
+ {
849
+ MessageType = "authentication_request" ,
850
+ Version = "1.0" ,
851
+ Payload = new Payload
852
+ {
853
+ MessageId = "12345" ,
854
+ Timestamp = 1757410647
855
+ }
856
+ } ;
857
+
858
+ Headers headers = new Headers ( ) ;
859
+ var bytes = serializer . SerializeAsync ( msg , new SerializationContext ( MessageComponentType . Value , testTopic , headers ) ) . Result ;
860
+ var result = deserializer . DeserializeAsync ( bytes , false , new SerializationContext ( MessageComponentType . Value , testTopic , headers ) ) . Result ;
861
+
862
+ Assert . Equal ( "12345-suffix" , result . Payload . MessageId ) ;
863
+ }
864
+
760
865
[ Fact ]
761
866
public void CELFieldTransformWithDef ( )
762
867
{
@@ -1404,4 +1509,23 @@ class Address
1404
1509
public int DoorNumber { get ; set ; }
1405
1510
public string DoorPin { get ; set ; }
1406
1511
}
1512
+
1513
+ class Message
1514
+ {
1515
+ [ JsonProperty ( "messageType" ) ]
1516
+ public string MessageType { get ; set ; }
1517
+ [ JsonProperty ( "version" ) ]
1518
+ public string Version { get ; set ; }
1519
+ [ JsonProperty ( "payload" ) ]
1520
+ public Payload Payload { get ; set ; }
1521
+ }
1522
+
1523
+ class Payload
1524
+ {
1525
+ [ JsonProperty ( "messageId" ) ]
1526
+ public string MessageId { get ; set ; }
1527
+ [ JsonProperty ( "timestamp" ) ]
1528
+ public int Timestamp { get ; set ; }
1529
+ }
1530
+
1407
1531
}
0 commit comments