RikHeijdens commented on code in PR #1968:
URL: https://github.com/apache/avro/pull/1968#discussion_r1023670948
##########
lang/rust/avro/src/types.rs:
##########
@@ -2391,4 +2417,148 @@ 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?
+ //assert!(test_value.resolve(&schema).is_ok(), "test_value should
resolve");
Review Comment:
@martin-g Note my attempt at a fix in
https://github.com/apache/avro/pull/1968/commits/f2d778d8469b337b14ceee9066016da842d39aaa
does not allow the schema to resolve where as this is the case in the test
below which does not use a namespace, therefore I believe this may require more
work.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]