@@ -577,12 +577,12 @@ public void CELFieldTransform()
577
577
schema . RuleSet = new RuleSet ( new List < Rule > ( ) ,
578
578
new List < Rule >
579
579
{
580
- new Rule ( "testCEL" , RuleKind . Transform , RuleMode . Write , "CEL_FIELD" , null , null ,
580
+ new Rule ( "testCEL" , RuleKind . Transform , RuleMode . Write , "CEL_FIELD" , null , null ,
581
581
"typeName == 'STRING' ; value + '-suffix'" , null , null , false )
582
582
}
583
583
) ;
584
584
store [ schemaStr ] = 1 ;
585
- subjectStore [ "topic-value" ] = new List < RegisteredSchema > { schema } ;
585
+ subjectStore [ "topic-value" ] = new List < RegisteredSchema > { schema } ;
586
586
var config = new JsonSerializerConfig
587
587
{
588
588
AutoRegisterSchemas = false ,
@@ -607,6 +607,80 @@ public void CELFieldTransform()
607
607
Assert . Equal ( user . FavoriteNumber , result . FavoriteNumber ) ;
608
608
}
609
609
610
+ [ Fact ]
611
+ public void CELFieldTransformWithDef ( )
612
+ {
613
+ var schemaStr = @"{
614
+ ""$schema"" : ""http://json-schema.org/draft-07/schema#"",
615
+ ""additionalProperties"" : false,
616
+ ""definitions"" : {
617
+ ""Address"" : {
618
+ ""additionalProperties"" : false,
619
+ ""properties"" : {
620
+ ""DoorNumber"" : {
621
+ ""type"" : ""integer""
622
+ },
623
+ ""DoorPin"" : {
624
+ ""confluent:tags"" : [ ""PII"" ],
625
+ ""type"" : ""string""
626
+ }
627
+ },
628
+ ""type"" : ""object""
629
+ }
630
+ },
631
+ ""properties"" : {
632
+ ""Address"" : {
633
+ ""$ref"" : ""#/definitions/Address""
634
+ },
635
+ ""Name"" : {
636
+ ""confluent:tags"" : [ ""PII"" ],
637
+ ""type"" : ""string""
638
+ }
639
+ },
640
+ ""title"" : ""Sample Event"",
641
+ ""type"" : ""object""
642
+ }" ;
643
+ var schema = new RegisteredSchema ( "topic-value" , 1 , 1 , schemaStr , SchemaType . Json , null ) ;
644
+ schema . RuleSet = new RuleSet ( new List < Rule > ( ) ,
645
+ new List < Rule >
646
+ {
647
+ new Rule ( "testCEL" , RuleKind . Transform , RuleMode . Write , "CEL_FIELD" , new HashSet < string >
648
+ {
649
+ "PII"
650
+
651
+ } , null ,
652
+ "value + '-suffix'" , null , null , false )
653
+ }
654
+ ) ;
655
+ store [ schemaStr ] = 1 ;
656
+ subjectStore [ "topic-value" ] = new List < RegisteredSchema > { schema } ;
657
+ var config = new JsonSerializerConfig
658
+ {
659
+ AutoRegisterSchemas = false ,
660
+ UseLatestVersion = true
661
+ } ;
662
+ var serializer = new JsonSerializer < JsonPerson > ( schemaRegistryClient , config ) ;
663
+ var deserializer = new JsonDeserializer < JsonPerson > ( schemaRegistryClient ) ;
664
+
665
+ var address = new Address
666
+ {
667
+ DoorNumber = 100 ,
668
+ DoorPin = "1234"
669
+ } ;
670
+ var person = new JsonPerson ( )
671
+ {
672
+ Address = address ,
673
+ Name = "bob"
674
+ } ;
675
+
676
+ Headers headers = new Headers ( ) ;
677
+ var bytes = serializer . SerializeAsync ( person , new SerializationContext ( MessageComponentType . Value , testTopic , headers ) ) . Result ;
678
+ var result = deserializer . DeserializeAsync ( bytes , false , new SerializationContext ( MessageComponentType . Value , testTopic , headers ) ) . Result ;
679
+
680
+ Assert . Equal ( "bob-suffix" , result . Name ) ;
681
+ Assert . Equal ( "1234-suffix" , result . Address . DoorPin ) ;
682
+ }
683
+
610
684
[ Fact ]
611
685
public void CELFieldCondition ( )
612
686
{
@@ -1004,4 +1078,17 @@ class NewerCustomer
1004
1078
[ JsonProperty ( "title" ) ]
1005
1079
public string Title { get ; set ; }
1006
1080
}
1081
+
1082
+ class JsonPerson
1083
+ {
1084
+ public string Name { get ; set ; }
1085
+ public Address Address { get ; set ; }
1086
+
1087
+ }
1088
+
1089
+ class Address
1090
+ {
1091
+ public int DoorNumber { get ; set ; }
1092
+ public string DoorPin { get ; set ; }
1093
+ }
1007
1094
}
0 commit comments