You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by GitBox <gi...@apache.org> on 2022/11/18 12:35:52 UTC

[GitHub] [avro] RikHeijdens commented on a diff in pull request #1971: AVRO-3674: [Rust] Pass the correct enclosing namespace when validating and resolving

RikHeijdens commented on code in PR #1971:
URL: https://github.com/apache/avro/pull/1971#discussion_r1026383330


##########
lang/rust/avro/src/types.rs:
##########
@@ -2391,4 +2442,151 @@ Field with name '"b"' is not a member of the map items"#,
             "field b record is invalid against the schema"
         ); // this should pass, but doesn't
     }
+
+    #[test]
+    fn test_avro_3674_validate_namespace_resolution() {
+        use crate::ser::Serializer;
+        use serde::Serialize;
+
+        let schema = Schema::parse_str(
+            r#"{
+            "type": "record",
+            "name": "NamespacedMessage",
+            "namespace": "com.domain",
+            "fields": [
+                {
+                    "type": "record",
+                    "name": "field_a",
+                    "fields": [
+                        {
+                            "name": "enum_a",
+                            "type": {
+                                "type": "enum",
+                                "name": "EnumType",
+                                "symbols": [
+                                    "SYMBOL_1",
+                                    "SYMBOL_2"
+                                ],
+                                "default": "SYMBOL_1"
+                            }
+                        },
+                        {
+                            "name": "enum_b",
+                            "type": "EnumType"
+                        }
+                    ]
+                }
+            ]
+        }"#,
+        )
+        .unwrap();
+
+        #[derive(Serialize)]
+        enum EnumType {
+            #[serde(rename = "SYMBOL_1")]
+            Symbol1,
+            #[serde(rename = "SYMBOL_2")]
+            Symbol2,
+        }
+
+        #[derive(Serialize)]
+        struct FieldA {
+            enum_a: EnumType,
+            enum_b: EnumType,
+        }
+
+        #[derive(Serialize)]
+        struct NamespacedMessage {
+            field_a: FieldA,
+        }
+
+        let msg = NamespacedMessage {
+            field_a: FieldA {
+                enum_a: EnumType::Symbol2,
+                enum_b: EnumType::Symbol1,
+            },
+        };
+
+        let mut ser = Serializer::default();
+        let test_value: Value = msg.serialize(&mut ser).unwrap();
+        assert!(test_value.validate(&schema), "test_value should validate");
+        // TODO (rikheijdens): I believe this should also resolve?

Review Comment:
   Looks like this resolves now so I guess we can get rid of the comment :-)
   ```suggestion
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org